Udostępnij przez


SoapMethodAttribute Klasa

Definicja

Dostosowuje generowanie i przetwarzanie protokołu SOAP dla metody. Klasa ta nie może być dziedziczona.

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
Dziedziczenie
SoapMethodAttribute
Atrybuty

Przykłady

W poniższym przykładzie SoapMethodAttribute kodu pokazano, jak używać składowych w klasie w celu dostosowania generowania i przetwarzania protokołu SOAP dla metody.

#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);
    }
}

Uwagi

Obiekty docelowe atrybutu SoapMethodAttribute to metody, które można wywołać zdalnie. Zastosuj element , SoapMethodAttribute aby dostosować generowanie i przetwarzanie protokołu SOAP. Właściwości tego atrybutu umożliwiają programisty dostosowanie pola nagłówka HTTP protokołu SOAPAction w celu wskazania intencji żądania HTTP protokołu SOAP.

Konstruktorów

Nazwa Opis
SoapMethodAttribute()

Tworzy wystąpienie klasy SoapMethodAttribute.

Pola

Nazwa Opis
ProtXmlNamespace

Przestrzeń nazw XML, do której element docelowy bieżącego atrybutu SOAP jest serializowany.

(Dziedziczone od SoapAttribute)
ReflectInfo

Obiekt odbicia używany przez klasy atrybutów pochodzące z SoapAttribute klasy do ustawiania informacji o serializacji XML.

(Dziedziczone od SoapAttribute)

Właściwości

Nazwa Opis
Embedded

Pobiera lub ustawia wartość wskazującą, czy typ musi być zagnieżdżony podczas serializacji protokołu SOAP.

(Dziedziczone od SoapAttribute)
ResponseXmlElementName

Pobiera lub ustawia nazwę elementu XML do użycia dla odpowiedzi metody na metodę docelową.

ResponseXmlNamespace

Pobiera lub ustawia przestrzeń nazw elementu XML używaną do odpowiedzi metody na metodę docelową.

ReturnXmlElementName

Pobiera lub ustawia nazwę elementu XML używaną dla wartości zwracanej z metody docelowej.

SoapAction

Pobiera lub ustawia pole nagłówka SOAPAction używane z żądaniami HTTP wysyłanymi za pomocą tej metody. Ta właściwość nie jest obecnie implementowana.

TypeId

Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego elementu Attribute.

(Dziedziczone od Attribute)
UseAttribute

Pobiera lub ustawia wartość wskazującą, czy element docelowy bieżącego atrybutu będzie serializowany jako atrybut XML zamiast pola XML.

XmlNamespace

Pobiera lub ustawia przestrzeń nazw XML, która jest używana podczas serializacji zdalnych wywołań metody docelowej.

Metody

Nazwa Opis
Equals(Object)

Zwraca wartość wskazującą, czy to wystąpienie jest równe podanemu obiektowi.

(Dziedziczone od Attribute)
GetHashCode()

Zwraca wartość skrótu dla tego wystąpienia.

(Dziedziczone od Attribute)
GetType()

Type Pobiera bieżące wystąpienie.

(Dziedziczone od Object)
IsDefaultAttribute()

W przypadku zastąpienia w klasie pochodnej wskazuje, czy wartość tego wystąpienia jest wartością domyślną klasy pochodnej.

(Dziedziczone od Attribute)
Match(Object)

W przypadku zastąpienia w klasie pochodnej zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

(Dziedziczone od Attribute)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Dziedziczone od Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Dziedziczone od Object)

Implementacje interfejsów jawnych

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

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Dziedziczone od Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie obiektu, którego można użyć do pobrania informacji o typie interfejsu.

(Dziedziczone od Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Dziedziczone od Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Dziedziczone od Attribute)

Dotyczy