2010-10-29 25 views
0

,我有以下MessageContracts作为请求使用:WCF MessageContract名单系列化

<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,并且我们有一些应用程序,我们无法负担必须重新编译和重新分配。

感谢您的帮助!

+0

'Api2Information.Namespace'是在用我的服务方法也可以在命名空间下获取所有内容。给“PropertyList”添加一个名称空间并没有改变任何东西,这只是我试图让字符串正确地被命名空间。 – 2010-10-29 13:27:37

回答

0

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

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

在此处找到的答案http://msdn.microsoft.com/zh-cn/library/aa347850(v=VS.90).aspx – 2010-10-29 16:01:39