Implementing WCF Using the "Normal" Interface

Every article I read about performing an async implementation for a WCF service requires a change in interface for the WCF service (for example, the returned operation type goes from T to the task). However, I do not want to change the signature of the operation, because I have a client code that does not know anything about the type of Task <>. I just want the implementation to be synchronous.

I could implement existing synchronous input points by having a wrapper method that calls the internal implementation method of the asynchronous call and then waits, but it blocks the thread calling into the shell, and this defeats the goal of having an asynchronous implementation (which should free these threads so that they can serve other requests).

So, I need WCF to know that the implementation is asynchronous, but also know that the interface is missing.

+4
source share
2 answers

"Asynchronous" server does not affect the "asynchronous" client. For example, in a project that I'm working on right now, I have on a 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 a 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 great. WCF notice template Task XxxxAsyncand converts it to the end point with no return type Task<T>and a suffix Async. However, when an operation is performed in an operation, it can be handled with the help of things like await.

+8
source

, , . .

, ( ), , .

0

Source: https://habr.com/ru/post/1527741/


All Articles