Java Jax-ws-can';无法使用默认命名空间从操作中获取参数

Java Jax-ws-can';无法使用默认命名空间从操作中获取参数,java,web-services,namespaces,jax-ws,xml-namespaces,Java,Web Services,Namespaces,Jax Ws,Xml Namespaces,接口: @WebService @SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.ENCODED, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED) public interface WebServ { @WebMethod(action = "Sum", operationName = "Sum") public abstract

接口:

@WebService
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.ENCODED, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public interface WebServ {

    @WebMethod(action = "Sum", operationName = "Sum")
    public abstract String sum(@WebParam(name = "a") int a, @WebParam(name = "b") int b);

}

实施:

@WebService(endpointInterface = "com.company.wstest.WebServ")
public class WebServImpl implements WebServ {
    @Override
    public String sum(@WebParam(name = "a") int a, @WebParam(name = "b") int b) {
        return String.valueOf(a + b);
    }
}

出版:

String endPoint = "http://localhost:" + port + "/" + env;
Endpoint endpoint = Endpoint.publish(endPoint, new WebServImpl());
if (endpoint.isPublished()) {
    System.out.println("Web service published for '" + env + "' environment");
    System.out.println("Web service url: " + endPoint);
    System.out.println("Web service wsdl: " + endPoint + "?wsdl");
}

如果我从SoapUI发送这样的请求(由wsdl自动生成):


6.
7.
我得到了正确的答案:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:SumResponse xmlns:ns2="http://wstest.company.com/">
         <return>13</return>
      </ns2:SumResponse>
   </S:Body>
</S:Envelope>

13
但我真正需要的是用默认名称空间发送请求:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
   <Header/>
   <Body>
      <Sum xmlns="http://wstest.company.com/">
         <a>6</a>
         <b>7</b>
      </Sum>
   </Body>
</Envelope>

6.
7.
回应如下:

...
<return>0</return>
...
。。。
0
...
我如何理解此参数(a和b)为空。。这很奇怪,因为jax-ws解析的请求没有错误。它可以看到操作,但不能看到参数。有人知道问题出在哪里吗

原因:“a”和“b”从其父“Sum”继承命名空间“”。

解决方案:在@WebService和@WebParam中将它们设置为相同的targetNamespace(为“a”、“b”和“Sum”使用相同的默认命名空间):

...
<return>0</return>
...
@WebService(endpointInterface = "com.company.wstest.WebServ", targetNamespace = "http://wstest.company.com/")
public class WebServImpl implements WebServ {
    @Override
    public String sum(@WebParam(name = "a", targetNamespace = "http://wstest.company.com/") int a
                     ,@WebParam(name = "b", targetNamespace = "http://wstest.company.com/") int b) {
        return String.valueOf(a + b);
    }
}