Asynchronous implementation of WCF synchronous operation

I have a .net 4.5 WCF. I will rewrite the service implementation to use EF6 to access the database. This service has many customers and many challenges. I can not change the service contract and customers. Does it make sense to use Async EF operations like SaveAsync, at the end my service should return T not Task (due to old clients).

Update

Operating contract

[OperationContract]
public object AddEntity(object entity)
{
    using(var context = new MyContext())
    {
        context.Add(entity)
        var task = context.SaveChangesAsync()

        return task.Result;
    }
}

So even I use async, the thread will be blocked by task. Result. I cannot use this because the operation contract must be changed in order to return the task. How to implement such a scenario?

+4
source share
2

Async EF-, SaveAsync, T not Task (- ).

, WCF. , API . , :

WCF

+4
[OperationContract]
public async Task<object> AddEntityAsync(object entity)
{
    using(var context = new MyContext())
    {
        context.Add(entity)
        return await context.SaveChangesAsync();
    }
}

WCF - .

, SaveChangesAsync Task, a Task<object>, , ;)

+1

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


All Articles