SoapDocumentMethodAttribute 類別

定義

SoapDocumentMethodAttribute 套用於方法,指定往返於方法的 SOAP 訊息使用 Document 格式。

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

範例

下列程式碼範例會將 XML Web 服務方法的 GetUserName 訊息樣式 Document 設定為 。 此外,具有 Body SOAP 要求元素的 XML 元素和 SOAP 回應分別設定為 GetUserNameRequestGetUserNameResponse

<%@ WebService Language="C#" class="MyUser" %>
 using System;
 using System.Web.Services;
 using System.Web.Services.Protocols;
 
 public class MyUser : WebService {
 
       [ SoapDocumentMethod(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    
    
    <SoapDocumentMethod(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

備註

Web 服務描述語言 (WSDL) 定義 XML Web 服務方法呼叫作業的兩種樣式,可以在 SOAP 訊息中格式化: RPCDocumentDocument 是指根據 XSD 架構格式化 XML Web 服務方法。 此 Document 樣式是指將元素格式化 Body 為元素之後 Body 的一或多個訊息部分系列。 與 屬性確切決定 UseParameterStyle 個別訊息部分的方式。 屬性 Use 會決定參數是格式化 Encoded 還是 Literal 。 會 ParameterStyle 決定參數是封裝在元素後面的 Body 單一訊息元件內,還是每個參數是否為個別訊息元件。

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

這個屬性可以同時套用至伺服器上的 XML Web 服務方法,以及用戶端上 Proxy 類別的方法。

建構函式

SoapDocumentMethodAttribute()

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

SoapDocumentMethodAttribute(String)

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

屬性

Action

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

Binding

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

OneWay

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

ParameterStyle

取得或設定參數是否封裝於 SOAP 訊息之 XML 部分中 Body 項目之下的單一 XML 項目。

RequestElementName

取得或設定 XML Web Service 方法與 SOAP 要求關聯的 XML 項目,這是定義於服務描述來當做一個作業。

RequestNamespace

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

ResponseElementName

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

ResponseNamespace

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

TypeId

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

(繼承來源 Attribute)
Use

取得或設定 SOAP 訊息的 XML 部分內 XML Web Service 方法的參數格式。

方法

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)

適用於

另請參閱