Java 何时使用 SOAPBinding.ParameterStyle.BARE 和 SOAPBinding.ParameterStyle.WRAPPED
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21191079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
when to use SOAPBinding.ParameterStyle.BARE and SOAPBinding.ParameterStyle.WRAPPED
提问by sRaj
I am in confusion as when to use SOAPBinding.ParameterStyle.BARE and SOAPBinding.ParameterStyle.WRAPPED .and which binding style is more preferred.what are the differences between them.
我很困惑什么时候使用 SOAPBinding.ParameterStyle.BARE 和 SOAPBinding.ParameterStyle.WRAPPED 。以及哪种绑定风格更受欢迎。它们之间有什么区别。
采纳答案by kingAm
ParameterStyle.Bare and ParameterStyle.Wrapped affects your wsdl definitions of request and response messages only.
ParameterStyle.Bare 和 ParameterStyle.Wrapped 仅影响请求和响应消息的 wsdl 定义。
Lets take an example, we have a webservice with a method "test" which has 2 input "string1" and "string2" and it is returning a string as "rstring".
举个例子,我们有一个带有方法“test”的网络服务,它有2个输入“string1”和“string2”,它返回一个字符串作为“rstring”。
ParameterStyle.BAREYour parameter's name will be visible as part name in your wsdl.
ParameterStyle.BARE您的参数名称将在 wsdl 中显示为部件名称。
Request message:
请求消息:
<message name="test">
<part name="string1" element="tns:string1"/>
<part name="string2" element="tns:string2"/>
</message>
Response message:
响应消息:
<message name="testResponse">
<part name="rstring" element="tns:rstring"/>
</message>
In your xsd test and testResponse will be defined like below, and your wsdl element directly referring elements under test and test response from xsd.
在你的 xsd 测试和 testResponse 将被定义如下,你的 wsdl 元素直接引用被测元素和来自 xsd 的测试响应。
<xs:complexType name="test">
<xs:sequence>
<xs:element name="string1" type="xs:string" minOccurs="0"/>
<xs:element name="string2" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:complexType name="testResponse">
<xs:sequence>
<xs:element name="rstring" type="xs:string" minOccurs="0"/>
</xs:sequence>
ParameterStyle.WRAPPED
ParameterStyle.WRAPPED
In this style your request and response message will be wrapped in single input as "parameter" and output as "result". and they will refer that particular element in xsd for all elements within.
在这种样式中,您的请求和响应消息将作为“参数”包装在单个输入中,并作为“结果”输出。并且他们将引用 xsd 中的所有元素的特定元素。
Request message:
请求消息:
<message name="test">
<part name="parameters" element="tns:test"/>
</message>
Response message:
响应消息:
<message name="testResponse">
<part name="result" element="tns:testResponse"/>
</message>
In your xsd test and testResponse will be defined as same as above,
在您的 xsd 测试和 testResponse 将被定义为与上述相同,
<xs:complexType name="test">
<xs:sequence>
<xs:element name="string1" type="xs:string" minOccurs="0"/>
<xs:element name="string2" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:complexType name="testResponse">
<xs:sequence>
<xs:element name="rstring" type="xs:string" minOccurs="0"/>
</xs:sequence>
In above example , you can spot the difference. This is the only difference they implicate in wsdl. Note: Above example is explained for Document type soap binding, in RPC, no xsd is involved so RPC.Bare is applicable only.
在上面的示例中,您可以发现差异。这是它们在 wsdl 中唯一的区别。注意:上面的例子是针对文档类型soap绑定解释的,在RPC中,不涉及xsd,所以RPC.Bare只适用。
回答by lupchiazoem
The document/literal wrapped style is the best approach and is also the default. Wrapped document style with literal encoding has the following advantages:
There is no type encoding info.
Everything that appears in the soap:body is defined by the Schema, so you can easily validate the message.
You have the method name in the soap message.
Document/literal is WS-I compliant, but without the WS-I restriction that the SOAP.body should have only one Child. The wrapped pattern meets the WS-I restriction that the SOAP messages SOAP.body has only one Child.
But in few cases you might have to use another style. If you have overloaded operations, you cannot use the document/literal wrapped style. WSDL allows overloaded operations, but when you add the wrapped pattern to WSDL, you require an element to have the same name as the operation, and you cannot have two elements with the same name in XML. So you must use the document/literal, non-wrapped style or one of the RPC styles.
文档/文字包装样式是最好的方法,也是默认的。使用文字编码的 Wrapped 文档样式具有以下优点:
没有类型编码信息。
出现在 soap:body 中的所有内容都由 Schema 定义,因此您可以轻松验证消息。
您在soap消息中有方法名称。
Document/literal 符合 WS-I,但没有 WS-I 限制,即 SOAP.body 应该只有一个 Child。包装模式符合 WS-I 限制,即 SOAP 消息 SOAP.body 只有一个 Child。
但在少数情况下,您可能必须使用另一种样式。如果您有重载操作,则不能使用文档/文字包装样式。WSDL 允许重载操作,但是当您将包装模式添加到 WSDL 时,您需要一个元素与操作同名,并且在 XML 中不能有两个同名的元素。因此,您必须使用文档/文字、非包装样式或 RPC 样式之一。