Vla*_*hev 6 java rpc jax-ws xml-namespaces
玩具服务如下
@WebService(targetNamespace="http://www.example.org/stock")
@SOAPBinding(style=Style.RPC,parameterStyle=ParameterStyle.WRAPPED)
public class GetStockPrice {
@WebMethod(operationName="GetStockPrice",action="urn:GetStockPrice")
@WebResult(partName="Price")
public Double getPrice(
@WebParam(name="StockName")
String stock
) {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
JAX-WS生成的客户端创建SOAP消息,其中StockName参数没有命名空间:
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:GetStockPrice xmlns:ns2="http://www.example.org/stock">
<StockName>IBM</StockName>
</ns2:GetStockPrice>
</S:Body>
</S:Envelope>
Run Code Online (Sandbox Code Playgroud)
我希望并希望StockName生成为
<ns2:StockName>IBM</ns2:StockName>
Run Code Online (Sandbox Code Playgroud)
即在目标名称空间中,而不是在匿名名称空间中(ns2不是默认的,据我所知,从消息中可以看出).
我想知道如何让JAX-WS将目标命名空间添加到消息的嵌套元素中?
尝试将名称空间指定给WebParam注释时没有任何改变,因为在使用RPC时会忽略此参数.
或者......这是否意味着RPC风格的参数始终是匿名的?
UPDATE
傻我.部分解决了.我必须做的是
那是:
@WebService(targetNamespace="http://www.example.org/stock")
@SOAPBinding(style=Style.DOCUMENT,parameterStyle=ParameterStyle.WRAPPED)
public class GetStockPrice {
@WebMethod(operationName="GetStockPrice",action="urn:GetStockPrice")
@WebResult(partName="Price")
public Double getPrice(
@WebParam(name="StockName",targetNamespace="http://www.example.org/stock")
String stock
) {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
尽管如此,客户端仍然希望返回值没有任何命名空间,即使我尝试声明提供一个.这令人困惑.
根据 WSI-Basic Profile,此行为是正确的。如果你看:
http://www.ws-i.org/profiles/basicprofile-1.1.html#Part_Accessors
第 4.7.20 节,断言 R2735 特别指出,对于 RPC/Literal,部分访问器元素必须放置在没有命名空间的元素中。