简体   繁体   English

WCF Silverlight服务参考

[英]WCF Silverlight Service Reference

I have added a ServiceReference to my Silverlight app. 我已经在我的Silverlight应用程序中添加了ServiceReference。 I have called it, WcfServiceReference. 我称它为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. 我以为我应该能够引用client.GetSpendDataTotal(不是Async),但是它不可用。 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. Silverlight仅允许您使用异步方法使用WCF服务。 The general idea is that synchronous calls to external services tie up the UI thread and leave your app unresponsive until they return. 通常的想法是,对外部服务的同步调用会阻塞UI线程,并使您的应用程序无响应,直到它们返回为止。 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. 请查看此问题此博客文章,以获取有关Silverlight的更多讨论以及引导您使用异步服务调用的原因。 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. 埃里克·利珀特(Eric Lippert) 在MSDN杂志上有关即将到来的异步等待模式的文章中,对后台工作绑定UI线程的问题进行了很好的解释/讨论。 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. 这里要记住的主要事情是,不管后台可能进行多少有用的工作,如果UI没有响应,那么应用程序就用户而言就什么也不做。 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中使用异步WCF服务调用使您可以在等待结果的同时使用UI进行其他操作,而不必让用户怀疑为什么他们什么也不能做。

Silverlight doesn't allow non-asynchronous calls to services. Silverlight不允许非异步调用服务。 When you code Silverlight access to WCF services, think Asynchronous. 在对Silverlight对WCF服务的访问进行编码时,请考虑异步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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