SoapMethodAttribute Class

Customizes SOAP generation and processing for a method. This class cannot be inherited.

Namespace:  System.Runtime.Remoting.Metadata
Assembly:  mscorlib (in mscorlib.dll)

[AttributeUsageAttribute(AttributeTargets.Method)]
[ComVisibleAttribute(true)]
public sealed class SoapMethodAttribute : SoapAttribute

The target objects for the SoapMethodAttribute attribute are methods that can be remotely invoked. Apply the SoapMethodAttribute to customize SOAP generation and processing. Properties of this attribute allow the programmer to customize the SOAPAction HTTP header field to indicate the intent of the SOAP HTTP request.

The following code example shows how to use the members in the SoapMethodAttribute class to customize SOAP generation and processing for a method.

using System;
using System.Runtime.Remoting.Metadata;
using System.Security.Permissions;

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
{
[SecurityPermission(SecurityAction.Demand)]
    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);
    }
}
#using <mscorlib.dll>
#using <System.dll>
#using <System.Runtime.Remoting.dll>
using namespace System;
using namespace System::Runtime::Remoting::Metadata;

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

int main()
{
    // Get the method info object for the GetHello method.
    System::Reflection::MethodBase* getHelloMethod =
        __typeof(ExampleNamespace::ExampleClass)->GetMethod(S"GetHello");

    // Print the XML namespace for the invocation of this method.
    String* methodCallXmlNamespace =
        System::Runtime::Remoting::SoapServices::
            GetXmlNamespaceForMethodCall(getHelloMethod);
    Console::WriteLine(
        S"The XML namespace for the response of the method " 
        S"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(
        S"The XML namespace for the invocation of the method " 
        S"GetHello in ExampleClass is {0}.",
        methodResponseXmlNamespace);

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

System.Object
  System.Attribute
    System.Runtime.Remoting.Metadata.SoapAttribute
      System.Runtime.Remoting.Metadata.SoapMethodAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2015 Microsoft