.NET SOAP 序列化无界序列

发布于 2024-12-18 19:33:17 字数 1271 浏览 4 评论 0原文

我们有一个 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>
...

使用 XmlArrayXmlArrayItem 属性,我们可以控制 的名称> 元素,但无法达到所需的结构:

...
<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眉黛浅 2024-12-25 19:33:17

看来 .NET WCF 服务与我们的 WSDL 配合得不太好(WSDL 是手动创建的,重点关注 XSD 而不是 SOAP)。

让 SOAP API 与 .NET 配合使用的最简单方法是更改​​ WSDL 以使用 SOAP 数组类型,因此 变为 soap-enc:Arraysoap-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 a soap-enc:Array with soap-enc:arrayType="tns:OrderItem[]".

The resulting XML generated by the Service Reference's auto-generated code is then correct.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文