开发者

WCF MessageContract List Serialization

I have the following MessageContracts to use as a request:

<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 Prope开发者_C百科rty PropertyList() As List(Of String)
    ...
End Class

But when testing in SoapUI, the getLimited request body is being created as:

  <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>

Where v2 = Api2Information.Namespace. What I really want is for the strings contained within PropertyList to be namespaced as v2, not arr. Is there anyway for me to achieve that? I'm converting an ASMX service to use WCF and we have a few applications where we cannot afford to have to recompile and redistribute.

Thanks for your helps!


I found what I was looking for. Using a custom collection type like:

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

End Class

and replacing occurrences of it in my contracts like:

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

    Protected _propertyList As PropertyList

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

Produces the output:

  <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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜