MessageContractAttribute.WrapperNamespace Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene o establece el espacio de nombres del elemento contenedor del cuerpo del mensaje.
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
Valor de propiedad
El espacio de nombres del elemento contenedor.
Ejemplos
El siguiente ejemplo de código muestra el uso de MessageContractAttribute para controlar la estructura de envoltura SOAP para el mensaje de solicitud y el mensaje de respuesta, y el uso de MessageHeaderAttribute (para crear un encabezado SOAP para el mensaje de respuesta) y MessageBodyMemberAttribute (para especificar los cuerpos del mensaje de solicitud y respuesta). El ejemplo de código contiene un ejemplo de cada mensaje cuando se envía.
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
Comentarios
Utilice la propiedad WrapperNamespace para establecer el espacio de nombres del elemento contenedor.