共用方式為


SoapRpcMethodAttribute.Action 屬性

定義

取得或設定 SOAP 要求的 SOAPAction 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

屬性值

String

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

範例

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

<%@ WebService Language="C#" class="MyUser" %>
 using System;
 using System.Web.Services;
 using System.Web.Services.Protocols;
 
 public class MyUser : WebService {
 
       [ SoapRpcMethod(Action="http://www.contoso.com/Sample", 
           RequestNamespace="http://www.contoso.com/Request",
           RequestElementName="GetUserNameRequest",
           ResponseNamespace="http://www.contoso.com/Response",
           ResponseElementName="GetUserNameResponse")]
      [ WebMethod(Description="Obtains the User Name") ]
      public UserName GetUserName() {
           string temp;
           int pos;
           UserName NewUser = new UserName();
           
           // Get the full user name, including the domain name if applicable.
           temp = User.Identity.Name;
 
           // Determine whether the user is part of a domain by searching for a backslash.
           pos = temp.IndexOf("\\");
           
           // Parse the domain name out of the string, if one exists.
           if (pos <= 0)
                 NewUser.Name = User.Identity.Name;
           else {
               NewUser.Name = temp.Remove(0,pos+1);
                 NewUser.Domain = temp.Remove(pos,temp.Length-pos);
           } 
       return NewUser;
      }
 
 }   
 
 public class UserName {
 
     public string Name;
     public string Domain;
 }
<%@ WebService Language="VB" class="MyUser" %>
Imports System
Imports System.Web.Services
Imports System.Web.Services.Protocols

Public Class MyUser
    Inherits WebService    
    
    <SoapRpcMethod(Action := "http://www.contoso.com/Sample", _
    RequestNamespace := "http://www.contoso.com/Request", _
    RequestElementName := "GetUserNameRequest", _
    ResponseNamespace := "http://www.contoso.com/Response", _
    ResponseElementName := "GetUserNameResponse"), _
    WebMethod(Description := "Obtains the User Name")> _
    Public Function _
        GetUserName() As UserName
        
        Dim temp As String
        Dim pos As Integer
        Dim NewUser As New UserName()
        
        ' Get the full user name, including the domain name if applicable.
        temp = User.Identity.Name
        
        ' Determine whether the user is part of a domain by searching for a backslash.
        pos = temp.IndexOf("\")
        
        ' Parse the domain name out of the string, if one exists.
        If pos <= 0 Then
            NewUser.Name = User.Identity.Name
        Else
            NewUser.Name = temp.Remove(0, pos + 1)
            NewUser.Domain = temp.Remove(pos, temp.Length - pos)
        End If
        Return NewUser
    End Function
End Class 

Public Class UserName
    
    Public Name As String
    Public Domain As String
End Class

備註

屬性通常是 URI, Action 表示 SOAP 要求的意圖。 不過,SOAP 規格不會限制格式,以及 URI 是否參考現有的檔。 Web 服務器可以使用屬性的存在和內容 Action ,例如防火牆,以適當地篩選 HTTP 中的 SOAP 要求訊息。

根據預設,.NET Framework 1.1 版會針對針對 XML Web 服務產生的 WSDL 檔案中每個支援的 SOAP 系結,在 元素的 soap:operation 屬性中發佈 Action 屬性 soapAction 。 支援的 SOAP 系結是 SOAP 1.1。

如需詳細資訊,請參閱 W3C 網站上的 SOAP 規格。

適用於