gpt4 book ai didi

java - 网络服务 : Wrapped vs Bare - from Java WebServices Up and Running

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:54:12 24 4
gpt4 key购买 nike

我是网络服务的新手,正在阅读“Java WebServices Up and Running”一书。不知何故,我发现这让初学者有点困惑。在第 54 页,它做出了相互矛盾的陈述。

首先它说

In the unwrapped style, the parameters occur bare; that is, as a sequence of unwrapped XML subelements in the SOAP body. In the wrapped style, the parameters occur as wrapped XML subelements of an XML element with the name of the service operation

然后它说。

What may be surprising is that the structure of the underlying SOAP messages, both the request and the response, remain unchanged. For instance, the request message from the simplified client AmazonClientU is identical in structure to the request message from the complicated client AmazonClientW.

我试着写了一个示例程序,我清楚地看到了 Wrapped Style 和 Bare style 的 SOAP 消息之间的区别。 Bare 样式不包含 SOAP 主体中的操作名称。

有人请澄清。提前致谢..

最佳答案

This discussion在 Java Ranch 论坛上为我清除了它。特别是 Jason Irwin 制作的这个例子:

BARE 客户端生成的接口(interface)(使用 wsimport):

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)  
public interface IMathServer {
@WebMethod
@WebResult(name = "addNumsResponse")
public AddNumsResponse addNums(@WebParam(name = "addNums") AddNums parameters);
}

WRAPPED 客户端生成的接口(interface)(使用 wsimport):

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)  
public interface IMathServer {
@WebMethod
@WebResult(name = "addNumsResponse")
public int addNums(@WebParam(name = "num1") int num1, @WebParam(name = "num2") int num2);
}

这两段代码生成相同的消息:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">  
<S:Body>
<ns2:addNums xmlns:ns2="http://SoapStyles/">
<num1>1</num1>
<num2>2</num2>
</ns2:addNums>
</S:Body>
</S:Envelope>

正如 R Srini 在同一讨论中所说,包装的是参数,而不是代码。

生成客户端的唯一区别是您将在客户端中创建参数的方式,但它们都将根据服务 WSDL 生成相同的消息(包装或未包装)。

使用 BARE,您将只有一个顶部元素(参数),其中包含“子参数”。这一个 BARE 将直接发送(不“包装”它)。使用 WRAPPED 时,您将在第一级拥有所有这些“子参数”,并且客户端会自动将它们包装在另一个顶级元素中。

引用 Jason Irwin 的话:

Only one parameter was passed ("addNums") and it was "Bare" in the body. In the second, the parameters were "bare" in the code, but "wrapped" at run-time by JAX-WS.

希望这对您有所帮助!

关于java - 网络服务 : Wrapped vs Bare - from Java WebServices Up and Running,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14107485/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com