小编knk*_*knk的帖子

如何将不继承 BindingProvider 的对象显式转换为 BindingProvider 对象?

我有一个 Web 服务,我在其中使用客户端 API 中的服务接口对象操作 SOAP 标头。

我需要将端口对象类型转换为BindingProvider对象。但是我的端口对象没有直接继承那个类。那么JVM怎么可能不抱怨呢?

它也有效。ClassCastException 没有运行时错误

代码片段:

    public SearchDocument getSearchDocumentService(String wsdlUri, AuthBean auth){
    SearchDocument_Service serv = null;
    serv = SearchDocument_Service.getServiceInstance(wsdlUri);
    SearchDocument searchDoc = serv.getSearchDocument();

    populateAuthAndHandlerInfo((BindingProvider)searchDoc, auth);//how is it that jvm doesn't complain here
    return searchDoc;
    }

    private void populateAuthAndHandlerInfo(BindingProvider port, AuthBean auth) {
    Binding binding = port.getBinding();
              List<Handler> handlerList = binding.getHandlerChain();
              handlerList.add(new EDMSSoapAuthHandler());
              binding.setHandlerChain(handlerList);
        Map<String, Object> context = port.getRequestContext();
        context.put("clientAuthInfo", auth);
        }
Run Code Online (Sandbox Code Playgroud)

搜索文档.java:

    @WebService(name = "SearchDocument", targetNamespace = "http://services.abc.com/Technology/SearchDocument/service/v1")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@XmlSeeAlso({
    ObjectFactory.class …
Run Code Online (Sandbox Code Playgroud)

java web-services jax-ws soap-client jakarta-ee

2
推荐指数
1
解决办法
1464
查看次数

标签 统计

jakarta-ee ×1

java ×1

jax-ws ×1

soap-client ×1

web-services ×1