SoapDocumentMethodAttribute 类

对方法应用 SoapDocumentMethodAttribute 将指定发往该方法以及来自该方法的 SOAP 消息使用 Document 格式设置。

**命名空间:**System.Web.Services.Protocols
**程序集:**System.Web.Services(在 system.web.services.dll 中)

语法

声明
<AttributeUsageAttribute(AttributeTargets.Method)> _
Public NotInheritable Class SoapDocumentMethodAttribute
    Inherits Attribute
用法
Dim instance As SoapDocumentMethodAttribute
[AttributeUsageAttribute(AttributeTargets.Method)] 
public sealed class SoapDocumentMethodAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method)] 
public ref class SoapDocumentMethodAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Method) */ 
public final class SoapDocumentMethodAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Method) 
public final class SoapDocumentMethodAttribute extends Attribute

备注

Web 服务描述语言 (WSDL) 定义了两种在 SOAP 消息中对(它称之为操作的)XML Web services 方法进行格式化的样式:RPCDocumentDocument 是指根据 XSD 架构来格式化 XML Web services 方法。Document 样式是指将 Body 元素作为 Body 元素后的一系列消息部分来进行格式化。UseParameterStyle 属性确切地确定如何将单个消息分成几部分。Use 属性确定参数是格式化为 Encoded 还是 LiteralParameterStyle 确定参数是封装在 Body 元素后的单个消息部分中,还是每个参数是一个单个的消息部分。

有关详细信息,请参见 自定义 SOAP 消息的格式

该属性可同时应用于服务器上的 XML Web services 方法和客户端上代理类的方法。

示例

下面的代码示例将 GetUserName XML Web services 方法的消息样式设置为 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
<%@ 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;
 }

继承层次结构

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

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

SoapDocumentMethodAttribute 成员
System.Web.Services.Protocols 命名空间
SoapDocumentServiceAttribute
SoapRpcMethodAttribute
SoapRpcServiceAttribute
SoapBindingUse 枚举
SoapParameterStyle