次の方法で共有


SoapDocumentMethodAttribute クラス

SoapDocumentMethodAttribute をメソッドに適用することにより、そのメソッドとの間で送受信される SOAP メッセージに Document 書式を適用することを指定できます。

この型のすべてのメンバの一覧については、SoapDocumentMethodAttribute メンバ を参照してください。

System.Object
   System.Attribute
      System.Web.Services.Protocols.SoapDocumentMethodAttribute

<AttributeUsage(AttributeTargets.Method)>
NotInheritable Public Class SoapDocumentMethodAttribute   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Method)]
public sealed class SoapDocumentMethodAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Method)]
public __gc __sealed class SoapDocumentMethodAttribute : public   Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.Method)
class SoapDocumentMethodAttribute extends Attribute

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

Web サービス記述言語 (WSDL: Web Services Description Language) では、操作を呼び出す XML Web サービス メソッドの SOAP メッセージ内における書式として、 RPCDocument の 2 つのスタイルを定義しています。 Document は、XSD スキーマに従った XML Web サービス メソッドの書式を指定します。 Document スタイルは、 Body 要素を、 Body 要素の後に続く 1 つ以上の連続するメッセージ部分として書式指定することを表します。個別のメッセージ部分の詳細については、 Use プロパティと ParameterStyle プロパティを使用して指定します。 Use プロパティは、パラメータの書式として Encoded または Literal のいずれかを指定します。 ParameterStyle は、パラメータを Body 要素の後に続く単一のメッセージ部分にカプセル化するかどうか、または各パラメータを独立したメッセージ部分とするかどうかを指定します。

詳細については、「 SOAP メッセージのカスタマイズ 」を参照してください。

この属性は、サーバー上の XML Web サービス メソッドと、クライアント上のプロキシ クラスのメソッドの両方に適用できます。

使用例

[Visual Basic, C#] GetUserName XML Web サービス メソッドに対して、メッセージ スタイルを Document に設定するコード例を次に示します。また、SOAP 要求と SOAP 応答の Body 要素に関連付けられている XML 要素として、それぞれ GetUserNameRequestGetUserNameResponse が設定されています。

 
<%@ WebService Language="VB" class="MyUser" %>
Imports System
Imports System.Web.Services
Imports System.Web.Services.Protocols

Public Class MyUser
    Inherits WebService    
    
    <SoapDocumentMethod(Action := "https://www.contoso.com/Sample", _
    RequestNamespace := "https://www.contoso.com/Request", _
    RequestElementName := "GetUserNameRequest", _
    ResponseNamespace := "https://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
        
        ' Deterime 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


[C#] 
<%@ WebService Language="C#" class="MyUser" %>
 using System;
 using System.Web.Services;
 using System.Web.Services.Protocols;
 
 public class MyUser : WebService {
 
       [ SoapDocumentMethod(Action="https://www.contoso.com/Sample", 
           RequestNamespace="https://www.contoso.com/Request",
           RequestElementName="GetUserNameRequest",
           ResponseNamespace="https://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;
 
           // Deterime 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;
 }

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Web.Services.Protocols

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

アセンブリ: System.Web.Services (System.Web.Services.dll 内)

参照

SoapDocumentMethodAttribute メンバ | System.Web.Services.Protocols 名前空間 | SoapDocumentServiceAttribute | SoapRpcMethodAttribute | SoapRpcServiceAttribute | SoapBindingUse | SoapParameterStyle