SoapMethodAttribute Classe

Définition

Personnalise la génération et le traitement SOAP pour une méthode. Cette classe ne peut pas être héritée.

public ref class SoapMethodAttribute sealed : System::Runtime::Remoting::Metadata::SoapAttribute
[System.AttributeUsage(System.AttributeTargets.Method)]
public sealed class SoapMethodAttribute : System.Runtime.Remoting.Metadata.SoapAttribute
[System.AttributeUsage(System.AttributeTargets.Method)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class SoapMethodAttribute : System.Runtime.Remoting.Metadata.SoapAttribute
[<System.AttributeUsage(System.AttributeTargets.Method)>]
type SoapMethodAttribute = class
    inherit SoapAttribute
[<System.AttributeUsage(System.AttributeTargets.Method)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type SoapMethodAttribute = class
    inherit SoapAttribute
Public NotInheritable Class SoapMethodAttribute
Inherits SoapAttribute
Héritage
SoapMethodAttribute
Attributs

Exemples

L’exemple de code suivant montre comment utiliser les membres de la classe pour personnaliser la génération et le SoapMethodAttribute traitement SOAP d’une méthode.

#using <System.dll>
#using <System.Runtime.Remoting.dll>
using namespace System;
using namespace System::Runtime::Remoting::Metadata;

namespace ExampleNamespace
{
   public ref class ExampleClass
   {
   public:
      [SoapMethod(
         ResponseXmlElementName="ExampleResponseElement",
         ResponseXmlNamespace=
         "http://example.org/MethodResponseXmlNamespace",
         ReturnXmlElementName="HelloMessage",
         SoapAction="http://example.org/ExampleSoapAction#GetHello",
         XmlNamespace="http://example.org/MethodCallXmlNamespace")]
      String^ GetHello( String^ name )
      {
         return String::Format( L"Hello, {0}", name );
      }
   };

}

int main()
{
   
   // Get the method info object for the GetHello method.
   System::Reflection::MethodBase^ getHelloMethod = 
      ExampleNamespace::ExampleClass::typeid->GetMethod( L"GetHello" );
   
   // Print the XML namespace for the invocation of this method.
   String^ methodCallXmlNamespace =
      System::Runtime::Remoting::SoapServices::GetXmlNamespaceForMethodCall(
         getHelloMethod );
   Console::WriteLine( L"The XML namespace for the response of the method "
         L"GetHello in ExampleClass is {0}.", methodCallXmlNamespace );
   
   // Print the XML namespace for the response of this method.
   String^ methodResponseXmlNamespace =
      System::Runtime::Remoting::SoapServices::GetXmlNamespaceForMethodCall(
         getHelloMethod );
   Console::WriteLine( L"The XML namespace for the invocation of the method "
         L"GetHello in ExampleClass is {0}.", methodResponseXmlNamespace );
   
   // Print the SOAP action for this method.
   String^ getHelloSoapAction =
      System::Runtime::Remoting::SoapServices::GetXmlNamespaceForMethodCall(
         getHelloMethod );
   Console::WriteLine( L"The SOAP action for the method "
         L"GetHello in ExampleClass is {0}.", getHelloSoapAction );
}
using System;
using System.Runtime.Remoting.Metadata;

namespace ExampleNamespace
{
    public class ExampleClass
    {
        [SoapMethod(
             ResponseXmlElementName="ExampleResponseElement",
             ResponseXmlNamespace=
                "http://example.org/MethodResponseXmlNamespace",
             ReturnXmlElementName="HelloMessage",
             SoapAction="http://example.org/ExampleSoapAction#GetHello",
             XmlNamespace="http://example.org/MethodCallXmlNamespace")]
        public string GetHello(string name)
        {
            return "Hello, " + name;
        }
    }
}

public class Demo
{
    public static void Main(string[] args)
    {
        // Get the method info object for the GetHello method.
        System.Reflection.MethodBase getHelloMethod =
            typeof(ExampleNamespace.ExampleClass).GetMethod("GetHello");

        // Print the XML namespace for the invocation of this method.
        string methodCallXmlNamespace =
            System.Runtime.Remoting.SoapServices.
                GetXmlNamespaceForMethodCall(getHelloMethod);
        Console.WriteLine(
            "The XML namespace for the response of the method " +
            "GetHello in ExampleClass is {0}.",
            methodCallXmlNamespace);

        // Print the XML namespace for the response of this method.
        string methodResponseXmlNamespace =
            System.Runtime.Remoting.SoapServices.
                GetXmlNamespaceForMethodResponse(getHelloMethod);
        Console.WriteLine(
            "The XML namespace for the invocation of the method " +
            "GetHello in ExampleClass is {0}.",
            methodResponseXmlNamespace);

        // Print the SOAP action for this method.
        string getHelloSoapAction =
            System.Runtime.Remoting.SoapServices.
                GetSoapActionFromMethodBase(getHelloMethod);
        Console.WriteLine(
            "The SOAP action for the method " +
            "GetHello in ExampleClass is {0}.",
            getHelloSoapAction);
    }
}

Remarques

Les objets cibles de l’attribut SoapMethodAttribute sont des méthodes qui peuvent être appelées à distance. Appliquez le pour personnaliser la génération et le SoapMethodAttribute traitement SOAP. Les propriétés de cet attribut permettent au programmeur de personnaliser le champ d’en-tête HTTP SOAPAction pour indiquer l’intention de la requête HTTP SOAP.

Constructeurs

SoapMethodAttribute()

Crée une instance de SoapMethodAttribute.

Champs

ProtXmlNamespace

Espace de noms XML dans lequel la cible de l'attribut SOAP actuel est sérialisée.

(Hérité de SoapAttribute)
ReflectInfo

Objet de réflexion utilisé par les classes d'attributs dérivées de la classe SoapAttribute pour définir les informations de sérialisation XML.

(Hérité de SoapAttribute)

Propriétés

Embedded

Obtient ou définit une valeur indiquant si le type doit être imbriqué lors de la sérialisation SOAP.

(Hérité de SoapAttribute)
ResponseXmlElementName

Obtient ou définit le nom d'élément XML à utiliser pour la réponse de la méthode à la méthode cible.

ResponseXmlNamespace

Obtient ou définit l’espace de noms d’éléments XML utilisé pour la réponse de la méthode à la méthode cible.

ReturnXmlElementName

Obtient ou définit le nom d'élément XML utilisé pour la valeur de retour de la méthode cible.

SoapAction

Obtient ou définit le champ d'en-tête SOAPAction utilisé avec les demandes HTTP envoyées avec cette méthode. Cette propriété n'est pas implémentée à l'heure actuelle.

TypeId

Lors de l'implémentation dans une classe dérivée, obtient un identificateur unique pour l'objet Attribute.

(Hérité de Attribute)
UseAttribute

Obtient ou définit une valeur indiquant si la cible de l'attribut actuel est sérialisée en tant qu'attribut XML au lieu de l'être en tant que champ XML.

XmlNamespace

Obtient ou définit l'espace de noms XML utilisé lors de la sérialisation des appels de méthode distants de la méthode cible.

Méthodes

Equals(Object)

Retourne une valeur qui indique si cette instance est égale à un objet spécifié.

(Hérité de Attribute)
GetHashCode()

Retourne le code de hachage de cette instance.

(Hérité de Attribute)
GetType()

Obtient le Type de l'instance actuelle.

(Hérité de Object)
IsDefaultAttribute()

En cas de substitution dans une classe dérivée, indique si la valeur de cette instance est la valeur par défaut pour la classe dérivée.

(Hérité de Attribute)
Match(Object)

En cas de substitution dans une classe dérivée, retourne une valeur indiquant si cette instance équivaut à un objet spécifié.

(Hérité de Attribute)
MemberwiseClone()

Crée une copie superficielle du Object actuel.

(Hérité de Object)
ToString()

Retourne une chaîne qui représente l'objet actuel.

(Hérité de Object)

Implémentations d’interfaces explicites

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

Mappe un jeu de noms avec un jeu correspondant d'identificateurs de dispatch.

(Hérité de Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Récupère les informations de type pour un objet, qui peuvent être utilisées pour obtenir les informations de type d'une interface.

(Hérité de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Récupère le nombre d'interfaces d'informations de type fourni par un objet (0 ou 1).

(Hérité de Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fournit l'accès aux propriétés et aux méthodes exposées par un objet.

(Hérité de Attribute)

S’applique à