MessageParameterAttribute Constructeur
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Initialise une nouvelle instance de la classe MessageParameterAttribute.
public:
MessageParameterAttribute();
public MessageParameterAttribute ();
Public Sub New ()
Exemples
L'exemple de code suivant indique l'utilisation de MessageParameterAttribute pour établir le nom du paramètre et la valeur de retour dans les métadonnées.
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>
'
L'exemple suivant montre le contrat de service généré pour le service précédent. Notez que le nom du paramètre est maintenant 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