.NET Framework Class Library
HttpMethodAttribute Class

Applying this attribute to an XML Web service client using HTTP-GET or HTTP-POST, sets the types that serialize the parameters sent to an XML Web service method and read the response from the XML Web service method. This class cannot be inherited.

Inheritance Hierarchy
SystemObject
   SystemAttribute
    System.Web.Services.ProtocolsHttpMethodAttribute

Namespace:   System.Web.Services.Protocols
Assembly:  System.Web.Services (in System.Web.Services.dll)
Syntax
<[%$TOPIC/2t94kk4e_en-us_VS_110_2_0_0_0_0%]([%$TOPIC/2t94kk4e_en-us_VS_110_2_0_0_0_1%].Method)> _
Public NotInheritable Class HttpMethodAttribute _
	Inherits [%$TOPIC/2t94kk4e_en-us_VS_110_2_0_0_0_2%]
[[%$TOPIC/2t94kk4e_en-us_VS_110_2_0_1_0_0%]([%$TOPIC/2t94kk4e_en-us_VS_110_2_0_1_0_1%].Method)]
public sealed class HttpMethodAttribute : [%$TOPIC/2t94kk4e_en-us_VS_110_2_0_1_0_2%]
[[%$TOPIC/2t94kk4e_en-us_VS_110_2_0_2_0_0%]([%$TOPIC/2t94kk4e_en-us_VS_110_2_0_2_0_1%]::Method)]
public ref class HttpMethodAttribute sealed : public [%$TOPIC/2t94kk4e_en-us_VS_110_2_0_2_0_2%]
[<[%$TOPIC/2t94kk4e_en-us_VS_110_2_0_3_0_0%]>]
[<[%$TOPIC/2t94kk4e_en-us_VS_110_2_0_3_0_1%]([%$TOPIC/2t94kk4e_en-us_VS_110_2_0_3_0_2%].Method)>]
type HttpMethodAttribute =  
    class 
        inherit [%$TOPIC/2t94kk4e_en-us_VS_110_2_0_3_0_3%] 
    end
public final class HttpMethodAttribute extends [%$TOPIC/2t94kk4e_en-us_VS_110_2_0_4_0_0%]

The HttpMethodAttribute type exposes the following members.

Constructors
  NameDescription
Public method HttpMethodAttributeInitializes a new instance of the HttpMethodAttribute class.
Public method HttpMethodAttribute(Type, Type)Initializes a new instance of the HttpMethodAttribute.
Top
Properties
  NameDescription
Public property ParameterFormatterGets or sets a Type that serializes parameters sent from an XML Web service client to the XML Web service method.
Public property ReturnFormatterGets or sets a Type that deserializes the response from an XML Web service method.
Public property TypeIdWhen implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)
Top
Methods
  NameDescription
Public method EqualsInfrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Public method GetHashCodeReturns the hash code for this instance. (Inherited from Attribute.)
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Public method IsDefaultAttributeWhen overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)
Public method MatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implemetation Private method _AttributeGetIDsOfNamesMaps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeGetTypeInfoRetrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeGetTypeInfoCountRetrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeInvokeProvides access to properties and methods exposed by an object. (Inherited from Attribute.)
Top
Remarks

If an XML Web service client calls an XML Web service method using HTTP-GET, ReturnFormatter must be set to XmlReturnReader and ParameterFormatter set to UrlParameterWriter. XML Web service clients invoking a XML Web service using HTTP-POST must set ReturnFormatter to XmlReturnReader and ParameterFormatter to HtmlFormParameterWriter.

Examples

The following example is a proxy class generated by the Wsdl.exe utility for calling an XML Web service utility using HTTP-POST. The Wsdl.exe automatically supplies the correct types for ReturnFormatter and ParameterFormatter, along with specifying that the proxy class inherits from HttpPostClientProtocol.

Public Class MyUser
    Inherits System.Web.Services.Protocols.HttpPostClientProtocol


    Public Sub New()
        Me.Url = "http://www.contoso.com/username.asmx" 
    End Sub 'New

    <HttpMethodAttribute(GetType(XmlReturnReader), GetType(HtmlFormParameterWriter))> _
    Public Function GetUserName() As UserName
        Return CType(Me.Invoke("GetUserName", Me.Url + "/GetUserName", New Object(0) {}), UserName)
    End Function 'GetUserName


    Public Function BeginGetUserName(callback As System.AsyncCallback, asyncState As Object) As System.IAsyncResult
        Return Me.BeginInvoke("GetUserName", Me.Url + "/GetUserName", New Object(0) {}, callback, asyncState)
    End Function 'BeginGetUserName


    Public Function EndGetUserName(asyncResult As System.IAsyncResult) As UserName
        Return CType(Me.EndInvoke(asyncResult), UserName)
    End Function 'EndGetUserName
End Class 'MyUser

<XmlRootAttribute(Namespace := "http://tempuri.org/", IsNullable := True)> _
Public Class UserName
    Public Name As String 
    Public Domain As String 

End Class 'UserName
public class MyUser : System.Web.Services.Protocols.HttpPostClientProtocol {

    public MyUser() {
        this.Url = "http://www.contoso.com/username.asmx";
    }

    [System.Web.Services.Protocols.HttpMethodAttribute(typeof(System.Web.Services.Protocols.XmlReturnReader), typeof(System.Web.Services.Protocols.HtmlFormParameterWriter))]
    public UserName GetUserName() {
        return ((UserName)(this.Invoke("GetUserName", (this.Url + "/GetUserName"), new object[0])));
    }

    public System.IAsyncResult BeginGetUserName(System.AsyncCallback callback, object asyncState) {
        return this.BeginInvoke("GetUserName", (this.Url + "/GetUserName"), new object[0], callback, asyncState);
    }

    public UserName EndGetUserName(System.IAsyncResult asyncResult) {
        return ((UserName)(this.EndInvoke(asyncResult)));
    }
}

[System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/", IsNullable=true)]
public class UserName {

    public string Name;

    public string Domain;
}
   
[System::Xml::Serialization::XmlRootAttribute(Namespace="http://tempuri.org/",IsNullable=true)]
public ref class UserName
{
public:
   String^ Name;
   String^ Domain;
};

public ref class MyUser: public System::Web::Services::Protocols::HttpPostClientProtocol
{
public:
   MyUser()
   {
      this->Url = "http://www.contoso.com/username.asmx";
   }

   [System::Web::Services::Protocols::HttpMethodAttribute(System::Web::Services::Protocols::XmlReturnReader::typeid,System::Web::Services::Protocols::HtmlFormParameterWriter::typeid)]
   UserName^ GetUserName()
   {
      return (dynamic_cast<UserName^>(this->Invoke( "GetUserName", (String::Concat( this->Url, "/GetUserName" )), gcnew array<Object^>(0) )));
   }

   System::IAsyncResult^ BeginGetUserName( System::AsyncCallback^ callback, Object^ asyncState )
   {
      return this->BeginInvoke( "GetUserName", (String::Concat( this->Url, "/GetUserName" )), gcnew array<Object^>(0), callback, asyncState );
   }

   UserName^ EndGetUserName( System::IAsyncResult^ asyncResult )
   {
      return (dynamic_cast<UserName^>(this->EndInvoke( asyncResult )));
   }
};
Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.