SoapRpcMethodAttribute 类
指定发送至和源自该方法的 SOAP 消息使用 RPC 格式设置。
**命名空间:**System.Web.Services.Protocols
**程序集:**System.Web.Services(在 system.web.services.dll 中)
语法
声明
<AttributeUsageAttribute(AttributeTargets.Method)> _
Public NotInheritable Class SoapRpcMethodAttribute
Inherits Attribute
用法
Dim instance As SoapRpcMethodAttribute
[AttributeUsageAttribute(AttributeTargets.Method)]
public sealed class SoapRpcMethodAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method)]
public ref class SoapRpcMethodAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Method) */
public final class SoapRpcMethodAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Method)
public final class SoapRpcMethodAttribute extends Attribute
备注
Web 服务描述语言 (WSDL) 定义了在 SOAP 消息中设置 XML Web services 方法或操作的格式的两种样式:RPC 和 Document。RPC 格式设置是指根据用于 RPC 的 SOAP 的 SOAP 规范设置操作的格式;也就是 SOAP 规范的第 7 节。RPC 格式设置规定,所有参数都封装在以 XML Web services 方法命名的单个 XML 元素中,并且该 XML 元素中的每个 XML 元素都表示一个以它所表示的参数命名的参数。
RPC 和 Document 样式的 SOAP 消息都可通过“远程过程调用 (RPC)”方式与 XML Web services 通信;但 Document 格式可用来以松散连接方式方便地进行通信。因此,建议使用 Document 样式的 XML Web services。有关详细信息,请参见 Customizing SOAP Messages 主题。
有关详细信息,请参见 自定义 SOAP 消息的格式。
该属性可应用于服务器上的 XML Web services 方法和客户端上的代理类。将 OneWay 属性设置为 true 的 XML Web services 方法不能访问它们的 HttpContext。这样,访问 WebService 类的任何属性将返回 空引用(在 Visual Basic 中为 Nothing)。
示例
下面的代码示例将 GetUserName
XML Web services 方法的消息样式设置为 Rpc。
<%@ WebService Language="VB" class="MyUser" %>
Imports System
Imports System.Web.Services
Imports System.Web.Services.Protocols
Public Class MyUser
Inherits WebService
<SoapRpcMethod(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
' 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
<%@ WebService Language="C#" class="MyUser" %>
using System;
using System.Web.Services;
using System.Web.Services.Protocols;
public class MyUser : WebService {
[ SoapRpcMethod(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;
// 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;
}
继承层次结构
System.Object
System.Attribute
System.Web.Services.Protocols.SoapRpcMethodAttribute
线程安全
此类型的任何公共静态(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
请参见
参考
SoapRpcMethodAttribute 成员
System.Web.Services.Protocols 命名空间
SoapDocumentMethodAttribute 类
SoapRpcServiceAttribute
SoapDocumentServiceAttribute 类