MessageContractAttribute.WrapperNamespace 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置消息正文包装元素的命名空间。
public:
property System::String ^ WrapperNamespace { System::String ^ get(); void set(System::String ^ value); };
public string WrapperNamespace { get; set; }
member this.WrapperNamespace : string with get, set
Public Property WrapperNamespace As String
属性值
包装元素命名空间。
示例
下面的代码示例演示如何使用 MessageContractAttribute 来控制请求消息和响应消息的 SOAP 信封结构,以及如何使用 MessageHeaderAttribute(创建响应消息的 SOAP 标头)和 MessageBodyMemberAttribute(指定请求消息和响应消息的正文)。 此代码示例包含发送时的每个消息的示例。
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;
}
}
}
Imports System.Runtime.Serialization
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Namespace Microsoft.WCF.Documentation
<ServiceContract(Namespace := "Microsoft.WCF.Documentation")> _
Friend Interface IMessagingHello
<OperationContract(Action := "http://GreetingMessage/Action", ReplyAction := "http://HelloResponseMessage/Action")> _
Function Hello(ByVal msg As HelloGreetingMessage) As HelloResponseMessage
End Interface
<MessageContract> _
Public Class HelloResponseMessage
Private localResponse As String = String.Empty
Private extra As String = String.Empty
<MessageBodyMember(Name := "ResponseToGreeting", Namespace := "http://www.examples.com")> _
Public Property Response() As String
Get
Return localResponse
End Get
Set(ByVal value As String)
localResponse = value
End Set
End Property
<MessageHeader(Name := "OutOfBandData", Namespace := "http://www.examples.com", MustUnderstand:=True)> _
Public Property ExtraValues() As String
Get
Return extra
End Get
Set(ByVal value As String)
Me.extra = value
End Set
End Property
'
' 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>
' </s:Body>
' </s:Envelope>
'
End Class
<MessageContract> _
Public Class HelloGreetingMessage
Private localGreeting As String
<MessageBodyMember(Name := "Salutations", Namespace := "http://www.examples.com")> _
Public Property Greeting() As String
Get
Return localGreeting
End Get
Set(ByVal value As String)
localGreeting = value
End Set
End Property
End Class
'
' 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>
' </s:Body>
' </s:Envelope>
'
Friend Class MessagingHello
Implements IMessagingHello
Public Function Hello(ByVal msg As HelloGreetingMessage) As HelloResponseMessage Implements IMessagingHello.Hello
Console.WriteLine("Caller sent: " & msg.Greeting)
Dim responseMsg As New HelloResponseMessage()
responseMsg.Response = "Service received: " & msg.Greeting
responseMsg.ExtraValues = String.Format("Served by object {0}.", Me.GetHashCode().ToString())
Console.WriteLine("Returned response message.")
Return responseMsg
End Function
End Class
End Namespace
注解
使用 WrapperNamespace 属性可设置包装元素的命名空间。