MessageContractMemberAttribute.Name 屬性


指定對應於這個成員的項目名稱。Specifies the name of the element that corresponds to this member.

 property System::String ^ Name { System::String ^ get(); void set(System::String ^ value); };
public string Name { get; set; }
member this.Name : string with get, set
Public Property Name As String



對應至這個成員的項目名稱。The name of the element that corresponds to this member. 這個字串必須是有效的 XML 項目名稱。This string must be a valid XML element name.


下列程式碼範例示範自訂訊息合約,這個合約會使用 MessageContractAttributeMessageHeaderAttributeMessageBodyMemberAttribute 屬性,以建立自訂的強型別訊息當做參數使用。The following code examples demonstrate a custom message contract that uses the MessageContractAttribute, MessageHeaderAttribute, and MessageBodyMemberAttribute attributes to create custom, strongly-typed messages to use as parameters. 在此案例中,有三個序列化成 SOAP 訊息本文項目的資料成員:sourceAccounttargetAccount 以及 amount 值 (後者序列化成名稱為 transactionAmount 的項目)。In this case, there are three data members that are serialized into the body element of the SOAP message: sourceAccount, targetAccount, and the amount value, (which is serialized into an element with the name transactionAmount). 此外,IsAudited SOAP 標頭項目是位於 命名空間。In addition, the IsAudited SOAP header element resides in the namespace.


OperationAccount 型別還必須具有資料合約。The Operation and Account types must also have a data contract.

public class BankingTransaction  
  [MessageHeader] public Operation operation;  
  [MessageHeader(Namespace="")] public bool IsAudited;  
  [MessageBody] public Account sourceAccount;  
  [MessageBody] public Account targetAccount;  
  [MessageBody(Name="transactionAmount")] public int amount;