Every article I have read about doing an async implementation for a WCF service requires modifying the interface for the WCF service (e.g. the return type of the operation goes from T to Task). However, I don't want to modify the operation signature as I have client code that doesn't know anything about the Task<> type. I just want the implementation to be synchronous.
I could implement the existing synchronous entry points by having a 'wrapper' method that makes a call to an internal async implementation method and then does an await, but that would block the thread calling into the wrapper, and that defeats the purpose of having an async implementation (which is to free up those threads so that they can serve other requests).
So, I need WCF to know that the implementation is async, but also know that the interface is not.
The "Asyncness" of the server does not affect the "Asyncness" of the client. For example on a project I am working on right now I have the following on the server
[ServiceContract(Namespace = "http://example.com/Example/v1", ProtectionLevel = ProtectionLevel.EncryptAndSign)]
public interface IClientsUploader
{
[OperationContract()]
Task<Results> UploadClientsAsync(Database database, Client[] clients);
}
but on the client side I have the contract
[System.ServiceModel.ServiceContractAttribute(Namespace="http://example.com/Example/v1", ConfigurationName="Example.IClientsUploader")]
public interface IClientsUploader
{
[System.ServiceModel.OperationContractAttribute(Action="http://example.com/Example/v1/IClientsUploader/UploadClients", ReplyAction="http://example.com/Example/v1/IClientUploader/UploadClientsResponse")]
Example.DataStructures.Results UploadClients(Example.DataStructures.Database database, System.Collections.Generic.IEnumerable<Example.DataStructures.Client> clients);
}
And it works perfectly fine. WCF notices the Task
XxxxAsync
pattern and turns it in to a endpoint without the Task<T>
return type and Async
suffix. However when a operation comes in the operation can be processed using things like await
inside it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With