WCF (SOAP):异步服务操作

WCF (SOAP): async Service Operations

使用 WCF SOAP 服务时,visual studio 会在客户端消费者应用程序的服务器中自动创建方法的同步和异步版本。例如服务器中的这个非异步方法:

public Data GetData(){
 return data;
} 

可以同时用作

var i = client.GetData();

var i = await client.GetDataAsync();

现在我的问题是,在服务器端使用异步服务操作方法是否有益?我的意思是,如果将服务契约方法实现为异步,服务器端是否会有任何性能增强?

...if implementing the service contract methods as async, will there be any performance enhancement in the server side at all or not?

不,在服务器端不会有任何区别。客户端上的异步服务操作是纯粹的客户端实现。服务无法区分来电。

do you think implementation of IDisposable for the service would be beneficial or not

如果您谈论的是服务端代码,那么您将使用 ServiceHost 容器来 运行 您的服务,它已经实现了 IDisposable,或者它将被动态加载来自 IIS 或 WAS,在这种情况下,您无法控制正确的粒度来实现 IDisposable。

如果您的服务的内部代码在执行过程中使用了任何非托管资源,那么您将需要管理这些资源的处置,但这是 .net 101 并且不仅适用于 WCF。