Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my service reference only generate asynchronous methods?

I have a Service Reference (not a web reference) in VS2008 to a web service that I did not write. The reference works, but only asynchronous versions of each method are available for me to use.

In the "Configure Service Reference" dialog, the "Generate asynchronous operations" is checked and grayed out. First of all, I thought checking this box generated async methods in addition to, not instead of, blocking methods. Second, I've never seen it grayed out before.

I have experience writing both sides of both WCF and ASMX-era web services and have never seen this before. What could be causing this?

Thanks.

like image 582
Greg Smalter Avatar asked Jan 29 '09 21:01

Greg Smalter


3 Answers

I'd be willing to wager ten up-votes that it's because you're doing this in Silverlight. Unfortunately I don't have the tools installed so I can't test this theory, but I do know that service calls from Silverlight can only be asynchronous. Perhaps you are using a Silverlight project template and are creating the service reference there? Visual Studio might be smart enough to know not to generate blocking methods in such a situation.

For reference:

http://msdn.microsoft.com/en-us/library/cc197937(VS.95).aspx

like image 120
Randolpho Avatar answered Nov 20 '22 15:11

Randolpho


The Silverlight Plugin is running on the Browsers UI thread. If you did synchronous networking calls you would block the entire Browser UI thread. In Chrome this would result in a non-responding tab, in other browsers like IE, the entire browser would appear locked.

So by only supporting asynchronous networking you are forced to write your application in an asynchronous maner.

like image 40
Jonas Follesø Avatar answered Nov 20 '22 14:11

Jonas Follesø


Silverlight only generates async service calls. However check this CodeProject page out.

When I started working with Silverlight, it was something that threw me at first. Then I realised I should be changing my code to work with the async model. You dont want to be blocking the UI thread while you wait for a service call to return.

like image 2
geofftnz Avatar answered Nov 20 '22 15:11

geofftnz