【问题标题】:WCF Array SerializationWCF 数组序列化
【发布时间】:2009-04-14 12:44:04
【问题描述】:

我正在使用 WCF OperationContract,它将整数数组作为参数。它正在使用 basicHttpBinding。

我注意到从使用 Visual Studio“添加 Web 引用”生成的客户端生成的 SOAP 包含 xmlns,因此:

<ids>
  <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">100</string>
  <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">101</string>
  <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">102</string>
   ... etc
</ids>

这将增加带有大数组的序列化流的大小。有没有办法消除这个xmlns属性?

对于 WCF 客户端,生成的 SOAP 看起来更像我所期望的:

<ids xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <a:string>100</a:string>
  <a:string>101</a:string>
  <a:string>102</a:string>
  ... etc..
</ids>

【问题讨论】:

    标签: xml wcf


    【解决方案1】:

    不幸的是,这实际上是客户端代理的功能,而不是您的服务。在此示例中,您正在查看使用 XML 序列化与数据协定序列化的客户端。一种在使 XML 更紧凑方面比另一种更好。

    您可能对 WSE 3.0 中的类型生成器 (link) 运气更好但我不是 100% 的。

    您应该让我们知道您的决定。很有趣。

    【讨论】:

      【解决方案2】:

      我对序列化不太熟悉,但这可能是 SOAP 1.1 和 1.2 之间的区别吗?我打赌你可以指定任何一种格式。是否有令人信服的理由不只使用 WCF 客户端?

      【讨论】:

      • 我在这两种情况下都使用 SOAP 1.1 (basicHttpBinding)。我需要支持旧的非 WCF 客户端(.NET 3.0 并非随处安装)。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-26
      • 1970-01-01
      • 2019-12-10
      • 2014-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多