Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running synchronous methods in a web service

I am out of town unfortunately and cannot test something I need to convey to my associates, so I was hoping for some help.

When I create a service reference to a web service and check the asynchronous check box, I notice that even though my web service has all asynchronous methods in it, the proxy or metadata on the client also creates synchronous versions of the same method.

In other words, I have a method on my web service called GetCategoriesAsync. Even though there is no method written for GetCategories, the Reference.cs file on the client (inside the service reference) automatically generates it. I am also able to execute this method in the WCF Service Test Client.

My question is, am I able to have my choice of calling the synchronous or asynchronous method from my client and it will show up via intellisense? Obviously, this would assume calling the appropriate method with or without the async, Task and await keywords or not.

like image 587
sagesky36 Avatar asked Nov 01 '22 08:11

sagesky36


1 Answers

Server and client are separated by the network. Neither of the care what the other does to generate the bytes that the web-services protocol specifies. Neither of them can detect whether the other is synchronous or asynchronous.

Pick what you like.

You can have sync server-side implementations and async client-side stub methods. Just have the generator emit the async versions and you can call any service in an async way. "they will still show up via intellisense...?" - yes, everything you generate will show up, of course. Generate them if you need them.

TL;DR: If you want to use async methods, generate them and use them. You do not need to modify the server. If you do not own the server (maybe it is a 3rd party non-.NET server), you can still call it in an async way.

like image 177
usr Avatar answered Nov 04 '22 10:11

usr