Sign Up
RelaxBuddy helps you connect and share with the people in your life.

calling async methods from a wcf service

I need to name asynchronous methods from a WCF service, one thing like:

[ServiceContract]interface IService{ [OperationContract] int SomeMethod(int data);}int SomeMethod(int data){ var query = ... build LINQ query; var response = await query.ToListAsync(); return response.Length;}

I do not wish so as to add async to the IService interface or SomeMethod method. Using asynchronous methods is an inside factor that needs not to be mirrored within the interface.

How can I do this?

CLARIFICATION:

My drawback here is the usage of await in a non-async method. I don't need the service contract to switch (the buyer does not essentially know what async is), and I don't wish to separate the process into BeginSomeMethod and EndSomeMethod. I want one method that uses await internally.

#c #wcf #asynchronous #asyncawait
Last update on March 20, 6:37 am by QUINTON3312.

Whether the server is the use of sync or async code does no longer subject for the buyer. Client and server are separated by way of a neatly-specified cord-protocol (regularly SOAP). SOAP has no perception of asynchronous finishing touch.

You will have a sync server and an async shopper, or vice versa. <sturdy>The client can not even detect whether or not the server is sync or async. This is an implementation detail. The server generally is a wrist watch working Linux and also you continue to could not tell.

<robust>The taste of IO you employ is an implementation element and does now not affect the bytes that cross over the community.

<robust>So select what you prefer. The consumer can nonetheless use async IO to get admission to the server.

I'm undecided why that is that this type of surprise to folks. In other contexts this turns out very intuitive: You will have a asynchronous TCP server and a synchronous client. I can say new WebClient().DownloadString(url) and download a string synchronously from a internet-server that may be implemented in an asynchronous way. I can't even tell what server software is running.

<robust>Use Fiddler to have a look at what's going over the twine whilst you're creating a WCF call. There is not any perception of synchronous or asynchronous calls.

Under the hood, whilst you invoke a service asynchronously, the WCF consumer library the use of TCP sockets in an asynchronous approach. When you invoke synchronously, TCP sockets are becoming used with blocking off calls. That's all of the variation.

WCF generated purchasers will also be made to have asynchronous methods along with the synchronous methods. Select the "Generate asynchronous operations" choice within the UI. Now you have got each variations. Both absolutely useful.

Here's how you'll be able to convince yourself of this with an experiment: Write a sync server, and make contact with it each sync and async from the similar .NET shopper. Now write a 2d server asynchronously (in any taste you favor) and use the very same client code to name it.

Task and IAsyncResult aren't serializable over SOAP besides so it might probably't perhaps be the case that a Task is transmitted to the customer.

Last update on March 20, 6:37 am by ismael.
All times are GMT. The time now is 8:01 pm.