.NET SOAP 序列化无界序列
我们有一个 WSDL,其中包含以下类型定义:
...
<xsd:complexType name="OrderItem">
<xsd:all>
<xsd:element name="source" type="xsd:string" />
</xsd:all>
</xsd:complexType>
<xsd:complexType name="OrderItems">
<xsd:sequence>
<xsd:element name="item" type="tns:OrderItem" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
...
在 VS 2010 中将服务添加为服务引用时,OrderItems
类包含一个 item
属性,其类型为 订单项[]
。然后生成 SOAP 请求,如下所示:
...
<items>
<OrderItem>
<item>foo</item>
<item>bar</item>
</OrderItem>
</items>
...
使用 XmlArray
和 XmlArrayItem
属性,我们可以控制
和 的名称>
元素,但无法达到所需的结构:
...
<items>
<item>foo</item>
<item>bar</item>
</items>
...
我知道,如果 WSDL 指定类似
而不是无界序列,但鉴于上述是使用某些自定义序列化的唯一方法?
编辑:示例 WSDL 位于 https://gist.github.com/1422704
We have a WSDL which contains the following type definition:
...
<xsd:complexType name="OrderItem">
<xsd:all>
<xsd:element name="source" type="xsd:string" />
</xsd:all>
</xsd:complexType>
<xsd:complexType name="OrderItems">
<xsd:sequence>
<xsd:element name="item" type="tns:OrderItem" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
...
When adding the service as a Service Reference in VS 2010, the OrderItems
class contains an item
property which is of type OrderItem[]
. The SOAP request is then generated as follows:
...
<items>
<OrderItem>
<item>foo</item>
<item>bar</item>
</OrderItem>
</items>
...
Using the XmlArray
and XmlArrayItem
attributes we can control the names of the <OrderItem>
and <item>
elements respectively, but can't get to the desired structure:
...
<items>
<item>foo</item>
<item>bar</item>
</items>
...
I'm aware that this problem could be avoided if the WSDL specified something like <xsd:restriction base="soap-enc:Array">
rather than an unbounded sequence, but given the above is the only way forward to use some custom serialization?
EDIT: Example WSDL at https://gist.github.com/1422704
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来 .NET WCF 服务与我们的 WSDL 配合得不太好(WSDL 是手动创建的,重点关注 XSD 而不是 SOAP)。
让 SOAP API 与 .NET 配合使用的最简单方法是更改 WSDL 以使用 SOAP 数组类型,因此
变为soap-enc:Array
与soap-enc:arrayType="tns:OrderItem[]"
。由服务参考的自动生成代码生成的结果 XML 是正确的。
It seems that .NET WCF services do not play nice with our WSDL (which was manually created with a focus on the XSD and not on SOAP).
The easiest way to get the SOAP API to work with .NET was to alter the WSDL to use the SOAP array type, so
<items>
becomes asoap-enc:Array
withsoap-enc:arrayType="tns:OrderItem[]"
.The resulting XML generated by the Service Reference's auto-generated code is then correct.