SoapRpcMethodAttribute.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.
public:
property bool OneWay { bool get(); void set(bool value); };
public bool OneWay { get; set; }
member this.OneWay : bool with get, set
Public Property OneWay As Boolean
属性值
如果 XML Web services 客户端不等待 Web 服务器完成对 XML Web services 方法的处理,则为 true;否则为 false。true if the XML Web service client does not wait for the Web server to completely process an XML Web service method; otherwise, false. 默认值为 false。The default is false.
示例
下面的代码示例将 OneWay 属性设置为 true 。The following code example sets the OneWay property to true.
<%@ WebService Language="C#" Class="Stats" %>
using System.Web.Services;
using System.Web.Services.Protocols;
public class Stats: WebService {
[ SoapRpcMethod(OneWay=true) ]
[ WebMethod(Description="Starts nightly stats batch process.") ]
public void StartStatsCrunch() {
// Begin a process that takes a long time to complete.
}
}
<%@ WebService Language="VB" Class="Stats" %>
Imports System.Web.Services
Imports System.Web.Services.Protocols
Public Class Stats
Inherits WebService
<SoapRpcMethod(OneWay := True), _
WebMethod(Description := "Starts nightly stats batch process.")> _
Public Sub _
StartStatsCrunch()
' Begin a process that takes a long time to complete.
End Sub
End Class
注解
当 XML Web service 方法的 OneWay 属性设置为时 true ,XML Web service 客户端不必等待 Web 服务器完成处理 XML Web service 方法。When an XML Web service method has the OneWay property set to true, the XML Web service client does not have to wait for the Web server to finish processing the XML Web service method. 一旦 Web 服务器对进行反序列化 SoapServerMessage ,但在调用 XML Web service 方法之前,服务器将返回 HTTP 202 状态代码。As soon as the Web server has deserialized the SoapServerMessage, but before it invokes the XML Web service method, the server returns an HTTP 202 status code. HTTP 202 状态代码向客户端指示 Web 服务器已经开始处理消息。An HTTP 202 status code indicates to the client that the Web server has started processing the message. 因此,XML Web service 客户端不会收到 Web 服务器成功处理该消息的确认。Therefore, an XML Web service client receives no acknowledgment that the Web server successfully processed the message.
单向方法不能有返回值或任何 out 参数。One-way methods cannot have a return value or any out parameters.
如果使用的是 .NET Framework 版本 1.0 XML Web service 方法,这些方法应用了 SoapRpcMethodAttribute 或 SoapDocumentMethodAttribute 特性,并将 OneWay 属性设置为,则 true 不允许 HttpContext 使用静态 Current 属性访问这些方法。If you are using the .NET Framework version 1.0 XML Web service methods that have either the SoapRpcMethodAttribute or SoapDocumentMethodAttribute attribute applied to them with the OneWay property set to true, do not allow access to their HttpContext using the static Current property. 若要访问 HttpContext ,请派生类实现 XML Web service 方法, WebService 并访问 Context 属性。To access the HttpContext, derive the class implementing the XML Web service method from WebService and access the Context property.