Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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.

Namespace:  System.Web.Services.Protocols
Assembly:  System.Web.Services (in System.Web.Services.dll)

[AttributeUsageAttribute(AttributeTargets.Method)]
public sealed class HttpMethodAttribute : Attribute

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.

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 : 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=S"http://tempuri.org/", IsNullable=true)]
public __gc class UserName {

public:
    String* Name;
    String* Domain;
};

public __gc class MyUser : public System::Web::Services::Protocols::HttpPostClientProtocol {

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

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

    System::IAsyncResult* BeginGetUserName(System::AsyncCallback* callback, Object* asyncState) {
        return this->BeginInvoke(S"GetUserName", (String::Concat( this->Url, S"/GetUserName" )), new Object*[0], callback, asyncState);
    }

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

System.Object
  System.Attribute
    System.Web.Services.Protocols.HttpMethodAttribute

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

Community Additions

ADD
Show:
© 2015 Microsoft