HttpMethodAttribute 類別

定義

藉著使用 HTTP-GET 或 HTTP-POST 將這個屬性套用到 XML Web Service 用戶端,設定型別以序列化傳送至 XML Web Service 方法的參數,及讀取來自 XML Web Service 方法的回應。 此類別無法獲得繼承。

public ref class HttpMethodAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Method)]
public sealed class HttpMethodAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Method, Inherited=true)]
public sealed class HttpMethodAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method)>]
type HttpMethodAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Method, Inherited=true)>]
type HttpMethodAttribute = class
    inherit Attribute
Public NotInheritable Class HttpMethodAttribute
Inherits Attribute
繼承
HttpMethodAttribute
屬性

範例

下列範例是由使用 HTTP-POST 呼叫 XML Web 服務公用程式的 Wsdl.exe 公用程式所產生的 Proxy 類別。 Wsdl.exe會自動提供 和 的正確型 ReturnFormatter 別,以及指定 Proxy 類別繼承自 HttpPostClientProtocolParameterFormatter

[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 )));
   }
};
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;
}
Public Class MyUser
    Inherits System.Web.Services.Protocols.HttpPostClientProtocol
    
    
    Public Sub New()
        Me.Url = "http://www.contoso.com/username.asmx"
    End Sub
    
    <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

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

End Class

備註

如果 XML Web 服務用戶端使用 HTTP-GET 呼叫 XML Web 服務方法,則必須設定為 XmlReturnReaderReturnFormatter 並將 ParameterFormatter 設定為 UrlParameterWriter 。 使用 HTTP-POST 叫用 XML Web 服務的 XML Web 服務用戶端必須將 設定 ReturnFormatterXmlReturnReader HtmlFormParameterWriterParameterFormatter

建構函式

HttpMethodAttribute()

初始化 HttpMethodAttribute 類別的新執行個體。

HttpMethodAttribute(Type, Type)

初始化 HttpMethodAttribute 的新執行個體。

屬性

ParameterFormatter

取得或設定 Type,這型別會將 XML Web Service 用戶端傳來的參數序列化至 XML Web Service 方法。

ReturnFormatter

取得或設定 Type,這型別還原序列化來自 XML Web Service 方法的回應。

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。

(繼承來源 Attribute)
GetHashCode()

傳回這個執行個體的雜湊碼。

(繼承來源 Attribute)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱