MessageBodyMemberAttribute Class
Assembly: System.ServiceModel (in system.servicemodel.dll)
'Declaration <AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field, Inherited:=False)> _ Public Class MessageBodyMemberAttribute Inherits MessageContractMemberAttribute 'Usage Dim instance As MessageBodyMemberAttribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field, Inherited=false) */ public class MessageBodyMemberAttribute extends MessageContractMemberAttribute
AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field, Inherited=false) public class MessageBodyMemberAttribute extends MessageContractMemberAttribute
Not applicable.
Use the MessageBodyMemberAttribute attribute to specify that a data member is serialized into the SOAP body and to control some serialization items.
The Order property is used to specify the order of body parts in cases where the default alphabetical order is not appropriate.
The other properties are inherited from the base class, System.ServiceModel.MessageContractMemberAttribute.
For information about controlling the serialization of the contents of a SOAP body without modifying the default SOAP envelope itself, see System.Runtime.Serialization.DataContractAttribute, Specifying Data Transfer in Service Contracts, and Data Contracts Overview.
For more information, see Using Message Contracts.
The following code example shows the use of the MessageContractAttribute to control the SOAP envelope structure for both the request message and the response message, and the use of both the MessageHeaderAttribute (to create a SOAP header for the response message) and the MessageBodyAttribute (to specify the bodies of both the request and response message). The code example contains an example of each message when sent.
using System; using System.Collections.Generic; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Channels; namespace Microsoft.WCF.Documentation { [ServiceContract(Namespace = "Microsoft.WCF.Documentation")] interface IMessagingHello { [OperationContract( Action = "http://GreetingMessage/Action", ReplyAction = "http://HelloResponseMessage/Action" )] HelloResponseMessage Hello(HelloGreetingMessage msg); } [MessageContract] public class HelloResponseMessage { private string localResponse = String.Empty; private string extra = String.Empty; [MessageBodyMember( Name = "ResponseToGreeting", Namespace = "http://www.examples.com")] public string Response { get { return localResponse; } set { localResponse = value; } } [MessageHeader( Name = "OutOfBandData", Namespace = "http://www.examples.com", MustUnderstand=true )] public string ExtraValues { get { return extra; } set { this.extra = value; } } /* The following is the response message, edited for clarity. <s:Envelope> <s:Header> <a:Action s:mustUnderstand="1">http://HelloResponseMessage/Action</a:Action> <h:OutOfBandData s:mustUnderstand="1" xmlns:h="http://www.examples.com">Served by object 13804354.</h:OutOfBandData> </s:Header> <s:Body> <HelloResponseMessage xmlns="Microsoft.WCF.Documentation"> <ResponseToGreeting xmlns="http://www.examples.com">Service received: Hello.</ResponseToGreeting> </HelloResponseMessage> </s:Body> </s:Envelope> */ } [MessageContract] public class HelloGreetingMessage { private string localGreeting; [MessageBodyMember( Name = "Salutations", Namespace = "http://www.examples.com" )] public string Greeting { get { return localGreeting; } set { localGreeting = value; } } } /* The following is the request message, edited for clarity. <s:Envelope> <s:Header> <!-- Note: Some header content has been removed for clarity. <a:Action>http://GreetingMessage/Action</a:Action> <a:To s:mustUnderstand="1"></a:To> </s:Header> <s:Body u:Id="_0" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <HelloGreetingMessage xmlns="Microsoft.WCF.Documentation"> <Salutations xmlns="http://www.examples.com">Hello.</Salutations> </HelloGreetingMessage> </s:Body> </s:Envelope> */ class MessagingHello : IMessagingHello { public HelloResponseMessage Hello(HelloGreetingMessage msg) { Console.WriteLine("Caller sent: " + msg.Greeting); HelloResponseMessage responseMsg = new HelloResponseMessage(); responseMsg.Response = "Service received: " + msg.Greeting; responseMsg.ExtraValues = String.Format("Served by object {0}.", this.GetHashCode().ToString()); Console.WriteLine("Returned response message."); return responseMsg; } } }
System.Attribute
System.ServiceModel.MessageContractMemberAttribute
System.ServiceModel.MessageBodyMemberAttribute
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.