共用方式為


SoapDocumentMethodAttribute.Action 屬性

定義

取得或設定 SOAPAction SOAP 請求的 HTTP 標頭欄位。

public:
 property System::String ^ Action { System::String ^ get(); void set(System::String ^ value); };
public string Action { get; set; }
member this.Action : string with get, set
Public Property Action As String

屬性值

SOAP SOAPAction 請求的 HTTP 標頭欄位。 預設為 http://tempuri.org/MethodName,其中 MethodName 是 XML Web 服務方法的名稱。

範例

以下程式碼範例將屬性 Action 設定為 http://www.contoso.com/GetUserName

<%@ WebService Language="C#" class="MyUser" %>
 
 using System.Web.Services;
 using System.Web.Services.Protocols;
 
 public class MyUser : WebService {
 
      [ SoapDocumentMethod(Action="http://www.contoso.com/GetUserName")]
      public string GetUserName() {
       return User.Identity.Name;
      }
 }
<%@ WebService Language="VB" class="MyUser" %>

Imports System.Web.Services
Imports System.Web.Services.Protocols

Public Class MyUser
    Inherits WebService
        
    <SoapDocumentMethod(Action := "http://www.contoso.com/GetUserName")> _
    Public Function _
        GetUserName() As String
        
        Return User.Identity.Name
    End Function
End Class

備註

通常,該 Action 屬性是表示請求意圖的 URI。 然而,SOAP 規範對 URI 的格式或是否可解析性沒有限制。 該屬性的存在與內容 Action 可被網頁伺服器(如防火牆)用來適當過濾 HTTP 中的 SOAP 請求訊息。

預設情況下,.NET Framework 1.1 版本會在為 XML Web 服務產生的 WSDL 文件中,針對每個支援的 SOAP 綁定元素屬性發布Action該屬性soapActionsoap:operation。 欲了解更多資訊,請參閱 W3C 網站上的 SOAP 規範。

適用於