SoapDocumentMethodAttribute 类

定义

对方法应用 SoapDocumentMethodAttribute 将指定发往该方法以及来自该方法的 SOAP 消息使用 Document 格式设置。Applying the SoapDocumentMethodAttribute to a method specifies that SOAP messages to and from the method use Document formatting.

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 service 方法的消息样式设置为 Document GetUserNameThe following code example sets the message style to Document for the GetUserName XML Web service method. 此外,具有 Body soap 请求和 soap 响应的元素的 XML 元素分别设置为 GetUserNameRequestGetUserNameResponseAdditionally, the XML element with the Body element for the SOAP request and SOAP response are set to GetUserNameRequest and GetUserNameResponse, respectively.

<%@ 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 service 方法调用操作的方式定义了两种样式,可以在 SOAP 消息中设置格式: RPCDocumentWeb Services Description Language (WSDL) defines two styles for how an XML Web service method, which it calls an operation, can be formatted in a SOAP message: RPC and Document. Document 指根据 XSD 架构格式化 XML Web service 方法。Document refers to formatting the XML Web service method according to an XSD schema. Document样式是指将元素格式化 Body 为元素后面的一个或多个消息部分的一系列 BodyThe Document style refers to formatting the Body element as a series of one or more message parts following the Body element. 和属性确定各个消息部分的具体方式 Use ParameterStyleExactly how the individual message parts is determined by the Use and ParameterStyle properties. Use属性确定参数的格式是否为 EncodedLiteralThe Use property determines whether parameters are formatted Encoded or Literal. ParameterStyle确定参数是在元素之后的单个消息部分中封装, Body 还是每个参数都是单个消息部分。The ParameterStyle determines whether the parameters are encapsulated within a single message part following the Body element or whether each parameter is an individual message part.

有关更多详细信息,请参阅 自定义 SOAP 消息格式For more details, see Customizing SOAP Message Formatting.

此特性可应用于服务器上的 XML Web service 方法和客户端上的代理类的方法。This attribute can be applied to both an XML Web service method on the server and a method of the proxy class on the client.

构造函数

SoapDocumentMethodAttribute()

初始化 SoapDocumentMethodAttribute 类的新实例。Initializes a new instance of the SoapDocumentMethodAttribute class.

SoapDocumentMethodAttribute(String)

初始化 SoapDocumentMethodAttribute 类的新实例,并将 Action 属性设置为 action 参数的值。Initializes a new instance of the SoapDocumentMethodAttribute class, setting the Action property to the value of the action parameter.

属性

Action

获取或设置 SOAP 请求的 SOAPActionHTTP 标头字段。Gets or sets the SOAPAction HTTP header field of the SOAP request.

Binding

获取或设置 XML Web services 方法正在为其实现操作的绑定。Gets or sets the binding an XML Web service method is implementing an operation for.

OneWay

获取或设置 XML Web services 客户端是否等待 Web 服务器完成对 XML Web services 方法的处理。Gets or sets whether an XML Web service client waits for the Web server to finish processing an XML Web service method.

ParameterStyle

获取或设置参数是否封装在 SOAP 消息的 XML 部分中 Body 元素下的单个 XML 元素中。Gets or sets whether parameters are encapsulated within a single XML element beneath the Body element in the XML portion of a SOAP message.

RequestElementName

获取或设置与 XML Web services 方法的 SOAP 请求相关联的 XML 元素,该元素在服务说明中定义为了一个操作。Gets or sets the XML element associated with the SOAP request for an XML Web service method, which is defined in a service description as an operation.

RequestNamespace

获取或设置与 XML Web services 方法的 SOAP 请求关联的命名空间。Gets or sets the namespace associated with the SOAP request for an XML Web service method.

ResponseElementName

获取或设置与 XML Web services 方法的 SOAP 响应关联的 XML 元素。Gets or sets the XML element associated with the SOAP response for an XML Web service method.

ResponseNamespace

获取或设置与 XML Web services 方法的 SOAP 响应关联的 XML 命名空间。Gets or sets the XML namespace associated with the SOAP response for an XML Web service method.

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)
Use

获取或设置 SOAP 消息的 XML 部分中的 XML Web services 方法的参数格式设置。Gets or sets the parameter formatting for an XML Web service method within the XML portion of a SOAP message.

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

(继承自 Attribute)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)

适用于

另请参阅