SoapRpcMethodAttribute 類別

定義

指定此方法往返傳送的 SOAP 訊息使用 RPC 格式。

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

範例

下列程式碼範例會將 XML Web 服務方法的 GetUserName 訊息樣式設定為 Rpc

<%@ 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 out the domain name from 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 out the domain name from 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

備註

Web 服務描述語言 (WSDL) 定義 XML Web 服務方法或作業的兩種樣式,可在 SOAP 訊息中格式化: RPCDocumentRPC 格式是指根據 SOAP 規格,針對 RPC 使用 SOAP 來格式化作業;否則稱為 SOAP 規格的第 7 節。 RPC 格式設定表示所有參數都封裝在 XML Web 服務方法之後所命名的單一 XML 專案內,而且該 XML 元素內的每個 XML 元素都代表名稱為 的參數,而該 XML 元素代表它所代表的參數。

以 和 Document 樣式格式化的 RPC SOAP 訊息可用來以遠端程序呼叫 (RPC) 方式與 XML Web 服務通訊;不過, Document 樣式也可以輕鬆地用來以鬆散結合的方式進行通訊。 因此, Document 建議使用樣式 XML Web 服務。 如需詳細資訊,請參閱 Customizing SOAP Messages 主題。

如需詳細資訊,請參閱 自訂 SOAP 訊息格式設定。

這個屬性可以套用至伺服器上的 XML Web 服務方法,以及用戶端上的 Proxy 類別。 屬性設定為 trueOneWay XML Web 服務方法無法存取其 HttpContext 。 因此,存取 類別的任何屬性 WebService 會傳回 null

建構函式

SoapRpcMethodAttribute()

初始化 SoapRpcMethodAttribute 類別的新執行個體,將所有屬性設定為它們的預設值。

SoapRpcMethodAttribute(String)

初始化 SoapRpcMethodAttribute 類別的新執行個體,將 Action 屬性設定為 action 參數的值。

屬性

Action

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

Binding

取得或設定 XML Web Service 方法實作作業的繫結。

OneWay

取得或設定 XML Web Service 用戶端是否等候 Web 伺服器完成處理 XML Web Service 方法。

RequestElementName

取得或設定與 XML Web Service 方法之 SOAP 要求關聯的 XML 項目。

RequestNamespace

取得或設定與 XML Web Service 方法之 SOAP 要求關聯的 XML 命名空間。

ResponseElementName

取得或設定與 XML Web Service 方法之 SOAP 回應關聯的 XML 項目。

ResponseNamespace

取得或設定與 XML Web Service 方法之 SOAP 回應關聯的 XML 命名空間。

TypeId

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

(繼承來源 Attribute)
Use

取得或設定叫用方法時使用的繫結。

方法

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)

適用於

另請參閱