如何:创建异步 Web 服务方法
来源:互联网 发布:java定义构造函数 编辑:程序博客网 时间:2024/05/24 15:39
本过程描述如何将 Web 服务方法转换为为异步访问设计的方法对。该过程遵循 .NET Framework 的异步设计模式。异步 XML Web 服务方法主题说明如何使用本过程以及 Wsdl.exe 工具如何生成可以异步访问 Web 服务方法的客户端代理类,即使这些类是针对同步访问而设计的。
实现异步 Web 服务方法
-
将一个异步 Web 服务方法拆分成两个方法;每个方法都有相同的基名称,一个以 Begin 开头,另一个以 End 开头。
-
Begin 方法的参数列表包含方法功能的所有 in 和 by reference 参数以及两个附加参数。
-
by reference 参数作为 in 参数列出。
-
倒数第二个参数必须为 AsyncCallback。AsyncCallback 参数允许客户端提供委托,在方法完成时将调用该委托。当一个异步 Web 服务方法调用另一个异步方法时,此参数可被传递到该方法的倒数第二个参数。
-
最后一个参数是 Object。Object 参数允许调用方为方法提供状态信息。当一个异步 Web 服务方法调用另一个异步方法时,此参数可以传递给该方法的最后一个参数。
-
返回值必须为 IAsyncResult 类型。
-
-
End 方法的参数列表包含 IAsyncResult 参数,此参数后面带有特定于方法功能的任何 out 和 by reference 参数。
-
返回值类型与异步 Web 服务方法的返回值类型相同。
-
by reference 参数作为 out 参数列出。
-
示例
C#
复制代码
using System;using System.Web.Services;
[WebService(Namespace=http://www.contoso.com/)]
public class MyService : WebService
...{
public RemoteService remoteService;
public MyService()
...{ // Create a new instance of proxy class for
// the Web service to be called.
remoteService = new RemoteService(); }
// Define the Begin method.
[WebMethod]
public IAsyncResult BeginGetAuthorRoyalties(String Author, AsyncCallback callback, object asyncState)
...{ // Begin asynchronous communictation with a different XML Web
// service.
return remoteService.BeginReturnedStronglyTypedDS(Author, callback,asyncState);
}
// Define the End method.
[WebMethod]
public AuthorRoyalties EndGetAuthorRoyalties(IAsyncResult asyncResult)
...{ // Return the asynchronous result from the other Web service.
return remoteService.EndReturnedStronglyTypedDS(asyncResult);
}
}
[WebService(Namespace=http://www.contoso.com/)]
public class MyService : WebService
...{
public RemoteService remoteService;
public MyService()
...{ // Create a new instance of proxy class for
// the Web service to be called.
remoteService = new RemoteService(); }
// Define the Begin method.
[WebMethod]
public IAsyncResult BeginGetAuthorRoyalties(String Author, AsyncCallback callback, object asyncState)
...{ // Begin asynchronous communictation with a different XML Web
// service.
return remoteService.BeginReturnedStronglyTypedDS(Author, callback,asyncState);
}
// Define the End method.
[WebMethod]
public AuthorRoyalties EndGetAuthorRoyalties(IAsyncResult asyncResult)
...{ // Return the asynchronous result from the other Web service.
return remoteService.EndReturnedStronglyTypedDS(asyncResult);
}
}
Visual Basic
复制代码
Imports System.Web.Services<WebService(Namespace:="http://www.contoso.com/")> _Public Class MyService Inherits WebService Public remoteService As RemoteService Public Sub New() MyBase.New() ' Create a new instance of proxy class for ' the Web service to be called. remoteService = New RemoteService() End Sub ' Define the Begin method. <WebMethod()> _ Public Function BeginGetAuthorRoyalties(ByVal Author As String, _ ByVal callback As AsyncCallback, ByVal asyncState As Object) _ As IAsyncResult ' Begin asynchronous communictation with a different XML Web ' service. Return remoteService.BeginReturnedStronglyTypedDS(Author, _ callback, asyncState) End Function ' Define the End method. <WebMethod()> _ Public Function EndGetAuthorRoyalties(ByVal asyncResult As _ IAsyncResult) As AuthorRoyalties ' Return the asynchronous result from the other Web service. Return remoteService.EndReturnedStronglyTypedDS(asyncResult) End FunctionEnd Class
- 如何:创建异步 Web 服务方法
- 如何:创建异步 Web 服务方法
- MattPowell介绍了如何在服务器端使用异步Web方法,来创建高性能的 Microsoft ASP.NET Web 服务
- 异步 XML Web 服务方法
- 异步调用Web服务方法
- ASP.NET创建Web服务之异步Web服务
- ASP.NET创建Web服务之异步Web服务
- 如何创建RESTFul Web服务
- ASP.NET创建Web服务之异步Web
- 如何创建和使用Web服务 [转帖]
- 如何创建和使用Web服务
- 如何创建和使用Web服务
- 如何创建和使用Web服务
- 如何创建并且使用Web服务
- 如何创建和使用Web服务
- 如何创建和使用Web服务
- ASP.NET创建Web服务之异步Web服务(二)
- ASP.NET创建Web服务之异步Web服务(一)
- 全面防御asp网站防黑客攻击
- typedef与函数指针
- 如何追踪系统入侵
- 我看德国公司IT部门与国内的差异
- 点石互动--Zac 之:新站点怎样寻找外部链接
- 如何:创建异步 Web 服务方法
- oracle9i10g上面怎样玩*.ora
- 《中国青年报》:宅青,中国闪现闷居一族
- centos使用光盘作为本地的yum源
- Java实现利用搜索引擎收集网址的程序
- Windows socket 代码例子
- Simple traversal of UDP over NATs
- ArcIMS安装过程中存在的问题
- 收集实用功能和经典的javaScript代码(包括部分正则)