【问题标题】:WCF MessageContract List SerializationWCF MessageContract 列表序列化
【发布时间】:2010-10-29 13:26:22
【问题描述】:

我有以下 MessageContracts 可用作请求:

<MessageContract(WrapperName:="get")> _
Public Class GetRequest
    Inherits BaseAuthenticatedRequest

    Protected _typeName As cEnum.eType
    Protected _id As Integer

    <MessageBodyMember()> _
    Public Property TypeName() As cEnum.eType
    ...

    <MessageBodyMember()> _
    Public Property Id() As Integer
    ...
End Class

<MessageContract(WrapperName:="getLimited")> _
Public Class GetLimitedRequest
    Inherits GetRequest

    Protected _propertyList As List(Of String)

    <MessageBodyMember(Namespace:=Api2Information.Namespace)> _
    Public Property PropertyList() As List(Of String)
    ...
End Class

但是在 SoapUI 中进行测试时,getLimited 请求正文被创建为:

  <v2:getLimited>
     <!--Optional:-->
     <v2:Id>?</v2:Id>
     <!--Optional:-->
     <v2:PropertyList>
        <!--Zero or more repetitions:-->
        <arr:string>?</arr:string>
     </v2:PropertyList>
     <!--Optional:-->
     <v2:TypeName>?</v2:TypeName>
  </v2:getLimited>

其中v2 = Api2Information.Namespace。我真正想要的是将 PropertyList 中包含的字符串命名为v2,而不是arr。无论如何我可以做到这一点吗?我正在将 ASMX 服务转换为使用 WCF,并且我们有一些应用程序无法重新编译和重新分发。

感谢您的帮助!

【问题讨论】:

  • Api2Information.Namespace 也用于我的服务方法,以获取命名空间下的所有内容。向PropertyList 添加命名空间并没有改变任何东西,这只是我尝试让字符串正确命名空间。

标签: wcf serialization soap messagecontract


【解决方案1】:

我找到了我要找的东西。使用自定义集合类型,例如:

<CollectionDataContract(Namespace:=Api2Information.Namespace)> _
Public Class PropertyList : Inherits List(Of String)

End Class

并在我的合同中替换它的出现,例如:

<MessageContract(WrapperName:="getLimited")> _
Public Class GetLimitedRequest
    Inherits GetRequest

    Protected _propertyList As PropertyList

    <MessageBodyMember(Namespace:=Api2Information.Namespace)> _
    Public Property PropertyList() As PropertyList
    ...
End Class

产生输出:

  <v2:getLimited>
     <!--Optional:-->
     <v2:Id>?</v2:Id>
     <!--Optional:-->
     <v2:PropertyList>
        <!--Zero or more repetitions:-->
        <v2:string>?</v2:string>
     </v2:PropertyList>
     <!--Optional:-->
     <v2:TypeName>?</v2:TypeName>
  </v2:getLimited>

【讨论】:

    猜你喜欢
    • 2012-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多