简体   繁体   中英

WCF Silverlight Service Reference

I have added a ServiceReference to my Silverlight app. I have called it, WcfServiceReference. I can code the following

    using ( var client = new WcfServiceReference.WcfDataServiceClient( ) )
    {
        client.GetSpendDataTotalAsync( Guid.NewGuid( ) );
    }

I was thinking I should be able to reference client.GetSpendDataTotal (not Async), but it isn't available. However, it is in the app - I can find it in my service... Probably something obvious?

Silverlight only allows you to consume WCF services using async methods. The general idea is that synchronous calls to external services tie up the UI thread and leave your app unresponsive until they return. Take a look at this question and this blog post for more discussion on Silverlight and why you're guided into using async service calls. To quote from the blog post, "the whole purpose of the plug-in architecture only permitting async requests is so that plug-ins would not be able to lock up the browser".

Eric Lippert gives an excellent explanation/discussion of the problem of background work tying up the UI thread in this MSDN Magazine article about the upcoming async-await pattern. Definitely worth reading.

The main thing to remember here is that regardless of how much useful work might be happening in the background, if the UI is unresponsive the app is doing nothing as far as the user is concerned. Using asynchronous WCF service calls in Silverlight allows you to do something else with the UI whilst waiting for the result rather than leaving the user wondering why they can't do anything.

Silverlight doesn't allow non-asynchronous calls to services. When you code Silverlight access to WCF services, think Asynchronous.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM