2014-04-04 60 views
1

如何定義消息合約以獲取此XML SOAP格式?如何定義消息合約以獲取此模式?

模式:

<List> 
     <Exclusions> 
     <ExclusionID>123</ExclusionID> 
     <ExclusionID>656</ExclusionID> 
     </Exclusions> 
     </List> 

我創建的類文件,如下一提,但它提供了不同的反應

<DataContract> _ 
Public Class List 


    ''' <remarks/> 
    Private _exclusions As Exclusions 

    <DataMember()> _ 
    Public Property Exclusions() As Exclusions 
     Get 
      Return _exclusions 
     End Get 
     Set(ByVal value As Exclusions) 
      _exclusions = value 
     End Set 
    End Property 

End Class 

<DataContract> 
Public Class Exclusions 

    <DataMember> 
    Public ExclusionID As ExclusionID() 

End Class 

<MessageContract> 
Public Class ExclusionID 

    <MessageBodyMember(Name:="")> 
    Public Value As String 

End Class 

我的回答是這樣的:

<List > 
     <Exclusions > 
     <ExclusionID> 
      <ExclusionID> 
      <Value>123</Value> 
      </ExclusionID> 
      <ExclusionID> 
      <Value>145</Value> 
      </ExclusionID> 
     </ExclusionID> 
     </Exclusions> 
    </List> 

如何才達到使用消息合約的正確消息?

回答

0

VB.net沒有安裝在我的VS.下面的C#代碼供您參考。

//類定義

public class List { 

    [MessageBodyMember] 
    public Exclusions Exclusions { get; set; } 
} 

[CollectionDataContract(Name="Exclusions", ItemName="Exclusion")] 
public class Exclusions : List<String> { 

} 

//help method 
static void WriteMessage(Message message, String filePath) { 
    using (var writer = new XmlTextWriter(filePath, Encoding.UTF8)) { 
     message.WriteMessage(writer); 
    } 
} 

//code 
var myList = new List(); 
myList.Exclusions = new Exclusions(); 
myList.Exclusions.Add("123"); 
myList.Exclusions.Add("656"); 

using (var message = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, 
    "http://127.0.0.1:3333/someaction", myList)) { 

    WriteMessage(message, "a.xml"); 
} 
相關問題