0

在异步模式下调用异步 Web 服务与在异步模式下调用同步 Web 服务有什么区别。我知道我们可以为 sycn 网络服务制作异步客户端。

sync 与 async web-services 的 wsdl 之间也有什么区别吗?

4

1 回答 1

2

一个 Web 服务可以被描述为同步还是异步取决于它的 API 以及它的 wsdl 描述。

byte[] GetImage()

是一个同步 Web 服务,而

String StartImageDownload()
bool IsComplete(String token)
byte[] ReadData(String token)

描述了一个异步接口。

无论接口的细节如何,来自代码的 API 调用可以是同步的或异步的。实际的 Web 服务调用是相同的,只是您的代码与网络层交互的方式不同。在同步调用中,您的调用线程会阻​​塞,直到数据返回(或发生错误)。在异步调用中,回调函数会通知您完成。实际的机制可能会有所不同,但它可能看起来像:

ws.BeginGetImage(()=>{
    // this is invoked when the result has arrived
    byte[] data = ws.EndGetImage();
});
// execution arrives here before the data does - the previous call doesn't block
于 2013-11-12T01:47:11.093 回答