2014-02-21 24 views
0

接口:JAX-WS不能从操作PARAMS与默认命名空间

@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生成)发送:

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

我得到正确的答案:

<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> 

但我真正需要的,这是送与默认的请求命名空间:

<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> 

和响应是:

... 
<return>0</return> 
... 

我怎么理解这个参数(a和b)为空......这很奇怪,因为jax-ws解析请求没有错误。它看到操作,但不参数。做一个人知道什么是问题?

回答

1

原因:“a”和“b”从其父“Sum”继承命名空间“http://wstest.company.com/”。

解决方案:摆列@WebService和@WebParam相同的目标(使用相同的默认命名空间为 “A”, “B” 和 “点心”):

@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); 
    } 
}