MessageParameterAttribute Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Controls the name of the request and response parameter names. Cannot be used with Message or message contracts.
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
- Inheritance
- Attributes
Examples
The following code example shows the use of MessageParameterAttribute to establish the name of the parameter and the return value in metadata.
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>
'
The following example shows the generated service contract for the preceding service. Note that the name of the parameter is now 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
Remarks
Use the MessageParameterAttribute to control the name of the parameter or the return value. This attribute has no effect if the parameters are marked by the MessageContractAttribute attribute.
Note
The value of the parameter names in the operation signature are part of the contract and are case sensitive. Use this attribute when you need to distinguish between the local parameter name and the metadata that describes the operation for client applications.
For more 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 Using Data Contracts.
For more information about creating message contracts, see Using Message Contracts.
Constructors
MessageParameterAttribute() |
Initializes a new instance of the MessageParameterAttribute class. |
Properties
Name |
Obtains or sets the name attribute of the parameter in the XML Schema (XSD). |
TypeId |
When implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute) |
Methods
Equals(Object) |
Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute) |
GetHashCode() |
Returns the hash code for this instance. (Inherited from Attribute) |
GetType() |
Gets the Type of the current instance. (Inherited from Object) |
IsDefaultAttribute() |
When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute) |
Match(Object) |
When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute) |
MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
ToString() |
Returns a string that represents the current object. (Inherited from Object) |
Explicit Interface Implementations
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Maps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute) |
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Retrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute) |
_Attribute.GetTypeInfoCount(UInt32) |
Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute) |
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Provides access to properties and methods exposed by an object. (Inherited from Attribute) |
Applies to
.NET