SOAP 请求 JAX-WS 生成了错误的命名空间 URI

SOAP Request JAX-WS wrong namespace URI generated

我想连接到 SOAP 服务。

我使用 wsimport 从远程 wsdl

生成了 类

我的代码:

    Lists listsService = new Lists();
    ListsSoap lisoap = listsService .getListsSoap(); 

    ((BindingProvider) si).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "MY_USER");
    ((BindingProvider) si).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "“MY_PASS");

    ((BindingProvider) si).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://<SOME_REMOTE_URL>/Lists.asmx");


   GetListCollectionResult coll = si.getListCollection();

我已经追踪到请求 xml:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap1="http://schemas.microsoft.com/sharepoint/soap/">
   <S:Header/>
   <S:Body>
      <soap1:GetListCollection/>
   </S:Body>
</S:Envelope>

http://schemas.xmlsoap.org/soap/envelope - 错了!

Returns 空结果,在 java 和 SOAP-UI

中都是

正确的 URI 应该是 http://www.w3.org/2003/05/soap-envelope

它在 SOAP-UI 中工作,但我不知道如何在 java 中为 JAX-WS

设置它

我怀疑它与 SOAP 版本 1 和 1.2 有关

更新:
尝试 运行 这个:

 soapEnv.setAttributeNS("http://schemas.xmlsoap.org/soap/envelope/", "S", "http://www.w3.org/2000/xmlns/");

但现在的输出是:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" ns0:S="http://www.w3.org/2000/xmlns/">

差不多好,但不够好

如果您使用 JAX-WS 从 WSDL 生成代码,URI 映射应该没问题,但使用 HTTP-BASIC 进行身份验证可能会导致您的代码出现问题。 也许这可以帮助:

JAX WS client cannot authenticate

它指的是身份验证问题。

解决方案很简单...

ListsSoap lisoap = listsService.getListsSoap12(); 

它 returns SOAP 1.2 的服务