MessageParameterAttribute Clase

Definición

Controla el nombre de los nombres de parámetros de respuesta y solicitud. No se puede utilizar con Message ni contratos de mensajes.

public ref class MessageParameterAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.ReturnValue, Inherited=false)]
public sealed class MessageParameterAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.ReturnValue, Inherited=false)>]
type MessageParameterAttribute = class
    inherit Attribute
Public NotInheritable Class MessageParameterAttribute
Inherits Attribute
Herencia
MessageParameterAttribute
Atributos

Ejemplos

El siguiente ejemplo de código muestra el uso de MessageParameterAttribute para establecer el nombre del parámetro y el valor devuelto en metadatos.

using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.Text;

namespace Microsoft.WCF.Documentation
{
  [ServiceContract(Namespace="http://microsoft.wcf.documentation")]
  public interface ISampleService{
    [OperationContract]
    [return:MessageParameter(Name = "Output")]
    string SampleMethod([MessageParameter(Name = "Input")]string msg);
  }

  /*
   The preceding use of MessageParameterAttribute generates the following XSD:

<?xml version="1.0" encoding="utf-8" ?>
  <xs:schema
    elementFormDefault="qualified"
    targetNamespace="http://microsoft.wcf.documentation"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:tns="http://microsoft.wcf.documentation">
    <xs:element name="SampleMethod">
      <xs:complexType>
        <xs:sequence>
          <xs:element minOccurs="0" name="Input" nillable="true" type="xs:string" />
        </xs:sequence>
      </xs:complexType>
    </xs:element>
    <xs:element name="SampleMethodResponse">
      <xs:complexType>
        <xs:sequence>
          <xs:element minOccurs="0" name="Output" nillable="true" type="xs:string" />
        </xs:sequence>
      </xs:complexType>
    </xs:element>
  </xs:schema>

   And the message sent is edited for clarity:
  <s:Body>
    <SampleMethod xmlns="http://microsoft.wcf.documentation">
      <Input>hello!</Input>
    </SampleMethod>
  </s:Body>
   */
Imports System.ServiceModel
Imports System.Text

Namespace Microsoft.WCF.Documentation
  <ServiceContract(Namespace:="http://microsoft.wcf.documentation")> _
  Public Interface ISampleService
    <OperationContract> _
    Function SampleMethod(<MessageParameter(Name := "Input")> ByVal msg As String) As <MessageParameter(Name := "Output")> String
  End Interface

'  
'   The preceding use of MessageParameterAttribute generates the following XSD:
'
'<?xml version="1.0" encoding="utf-8" ?> 
'  <xs:schema 
'    elementFormDefault="qualified" 
'    targetNamespace="http://microsoft.wcf.documentation" 
'    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
'    xmlns:tns="http://microsoft.wcf.documentation">
'    <xs:element name="SampleMethod">
'      <xs:complexType>
'        <xs:sequence>
'          <xs:element minOccurs="0" name="Input" nillable="true" type="xs:string" /> 
'        </xs:sequence>
'      </xs:complexType>
'    </xs:element>
'    <xs:element name="SampleMethodResponse">
'      <xs:complexType>
'        <xs:sequence>
'          <xs:element minOccurs="0" name="Output" nillable="true" type="xs:string" /> 
'        </xs:sequence>
'      </xs:complexType>
'    </xs:element>
'  </xs:schema>
'   
'   And the message sent is edited for clarity:
'  <s:Body>
'    <SampleMethod xmlns="http://microsoft.wcf.documentation">
'      <Input>hello!</Input>
'  </s:Body>   
'

El siguiente ejemplo de código muestra el contrato de servicio generado para el servicio precedente. Observe que el nombre del parámetro ahora es Input.

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://microsoft.wcf.documentation", ConfigurationName="ISampleService")]
public interface ISampleService
{

    [System.ServiceModel.OperationContractAttribute(
      Action="http://microsoft.wcf.documentation/ISampleService/SampleMethod",
      ReplyAction="http://microsoft.wcf.documentation/ISampleService/SampleMethodResponse"
    )]
    [return: System.ServiceModel.MessageParameterAttribute(Name="Output")]
    string SampleMethod(string Input);
}
<System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0"), _
System.ServiceModel.ServiceContractAttribute(Namespace:="http://microsoft.wcf.documentation", _
                                             ConfigurationName:="ISampleService")> _
Public Interface ISampleService

    <System.ServiceModel.OperationContractAttribute(Action:="http://microsoft.wcf.documentation/ISampleService/SampleMethod", _
                    ReplyAction:="http://microsoft.wcf.documentation/ISampleService/SampleMethodResponse")> _
    Function SampleMethod(ByVal Input As String) As <System.ServiceModel.MessageParameterAttribute(Name:="Output")> String
End Interface

Comentarios

Utilice el MessageParameterAttribute para controlar el nombre del parámetro o el valor devuelto. Este atributo no tiene efecto alguno si el atributo MessageContractAttribute marca los parámetros.

Nota

El valor de los nombres de parámetro en la firma de la operación forma parte del contrato y distingue entre mayúsculas y minúsculas. Utilice este atributo cuando necesite distinguir entre el nombre de parámetro local y los metadatos que describen la operación para las aplicaciones de cliente.

Para obtener más información sobre cómo controlar la serialización del contenido de un cuerpo SOAP sin modificar el sobre SOAP predeterminado, vea System.Runtime.Serialization.DataContractAttribute, Especificar transferencia de datos en contratos de servicio y Usar contratos de datos.

Para obtener más información sobre la creación de contratos de mensajes, vea Uso de contratos de mensajes.

Constructores

MessageParameterAttribute()

Inicializa una nueva instancia de la clase MessageParameterAttribute.

Propiedades

Name

Obtiene o establece el atributo de nombre del parámetro en el esquema XML (XSD).

TypeId

Cuando se implementa en una clase derivada, obtiene un identificador único para este Attribute.

(Heredado de Attribute)

Métodos

Equals(Object)

Devuelve un valor que indica si esta instancia es igual que un objeto especificado.

(Heredado de Attribute)
GetHashCode()

Devuelve el código hash de esta instancia.

(Heredado de Attribute)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
IsDefaultAttribute()

Si se reemplaza en una clase derivada, indica si el valor de esta instancia es el valor predeterminado de la clase derivada.

(Heredado de Attribute)
Match(Object)

Cuando se invalida en una clase derivada, devuelve un valor que indica si esta instancia es igual a un objeto especificado.

(Heredado de Attribute)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Implementaciones de interfaz explícitas

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Asigna un conjunto de nombres a un conjunto correspondiente de identificadores de envío.

(Heredado de Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Obtiene la información de tipos de un objeto, que puede utilizarse para obtener la información de tipos de una interfaz.

(Heredado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera el número de interfaces de información de tipo que proporciona un objeto (0 ó 1).

(Heredado de Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Proporciona acceso a las propiedades y los métodos expuestos por un objeto.

(Heredado de Attribute)

Se aplica a