SoapRpcMethodAttribute 类

定义

指定发送至和源自该方法的 SOAP 消息使用 RPC 格式设置。

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

示例

下面的代码示例设置 XML Web 服务方法的消息样式Rpc``GetUserName

<%@ WebService Language="C#" class="MyUser" %>
 using System;
 using System.Web.Services;
 using System.Web.Services.Protocols;
 
 public class MyUser : WebService {
 
       [ SoapRpcMethod(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 out the domain name from 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    
    
    <SoapRpcMethod(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 out the domain name from 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) 定义两种样式,用于在 SOAP 消息中设置 XML Web 服务方法或操作的格式: RPC Document RPC 格式是指根据 SOAP 规范设置操作的格式,以便使用 SOAP for RPC;否则称为 SOAP 规范的第 7 部分。 RPC 格式设置指出,所有参数都封装在 XML Web 服务方法命名的单个 XML 元素中,并且该 XML 元素中的每个 XML 元素都表示一个以它表示的参数命名的参数。

采用两种格式的 RPC Document SOAP 消息和样式都可用于以远程过程调用 (RPC) 方式与 XML Web 服务通信;但是 Document ,该样式也可以轻松地以松散耦合的方式进行通信。 因此, Document 建议使用样式 XML Web 服务。 有关更多详细信息,请参阅 Customizing SOAP Messages 主题。

有关详细信息,请参阅 自定义 SOAP 消息格式设置。

此属性可应用于服务器上的 XML Web 服务方法和客户端上的代理类。 将 OneWay 属性设置为 true 无权访问其 HttpContextXML Web 服务方法。 因此,访问类返回null的任何属性WebService

构造函数

SoapRpcMethodAttribute()

初始化 SoapRpcMethodAttribute 类的新实例,将所有属性都设置为其默认值。

SoapRpcMethodAttribute(String)

初始化 SoapRpcMethodAttribute 类的新实例,并将 Action 属性设置为 action 参数的值。

属性

Action

获取或设置 SOAP 请求的 SOAPActionHTTP 标头字段。

Binding

获取或设置 XML Web services 方法为其实现操作的绑定。

OneWay

获取或设置 XML Web services 客户端是否等待 Web 服务器完成对 XML Web services 方法的处理。

RequestElementName

获取或设置与 XML Web services 方法的 SOAP 请求关联的 XML 元素。

RequestNamespace

获取或设置与 XML Web services 方法的 SOAP 请求关联的 XML 命名空间。

ResponseElementName

获取或设置与 XML Web services 方法的 SOAP 响应关联的 XML 元素。

ResponseNamespace

获取或设置与 XML Web services 方法的 SOAP 响应关联的 XML 命名空间。

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。

(继承自 Attribute)
Use

获取或设置在调用该方法时所使用的绑定。

方法

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)

将一组名称映射为对应的一组调度标识符。

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

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

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

检索对象提供的类型信息接口的数量(0 或 1)。

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

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于

另请参阅