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

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

<%@ 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 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 訊息中格式化: RPC Document Document 是指根據 XSD 架構格式化 XML Web 服務方法。 此 Document 樣式是指將元素格式化 Body 為元素之後 Body 的一或多個訊息部分系列。 與 屬性確切決定 Use ParameterStyle 個別訊息部分的方式。 屬性 Use 會決定參數是格式化 Encoded 還是 Literal 。 會 ParameterStyle 決定參數是封裝在元素後面的 Body 單一訊息元件內,還是每個參數是否為個別訊息元件。

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

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