异步调用异步Web服务和异步调用同步Web服务有什么区别?

时间:2013-11-11 22:06:07

标签: c# wcf web-services asynchronous wsdl

在异步模式下调用异步Web服务与在异步模式下调用同步Web服务之间的区别是什么。我知道我们可以为sycn web-service创建异步客户端。

同步和异步网络服务的wsdl之间是否有任何区别?

1 个答案:

答案 0 :(得分: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
相关问题