本文整理匯總了C#中System.ServiceModel.MessageBodyMemberAttribute類的典型用法代碼示例。如果您正苦於以下問題:C# MessageBodyMemberAttribute類的具體用法?C# MessageBodyMemberAttribute怎麽用?C# MessageBodyMemberAttribute使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MessageBodyMemberAttribute類屬於System.ServiceModel命名空間,在下文中一共展示了MessageBodyMemberAttribute類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Hello
//引入命名空間
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;
}
}
}