0
@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解析請求沒有錯誤。它看到操作,但不參數。做一個人知道什麼是問題?