WCF Silverlight 服务参考
我已将 ServiceReference 添加到我的 Silverlight 应用程序中。我将其称为 WcfServiceReference。我可以编写以下代码,
using ( var client = new WcfServiceReference.WcfDataServiceClient( ) )
{
client.GetSpendDataTotalAsync( Guid.NewGuid( ) );
}
我认为我应该能够引用 client.GetSpendDataTotal (不是异步),但它不可用。然而,它在应用程序中 - 我可以在我的服务中找到它......可能是显而易见的事情?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Silverlight 只允许您使用异步方法使用 WCF 服务。总体思路是,对外部服务的同步调用会占用 UI 线程,并使您的应用程序在它们返回之前无响应。看看这个问题和此博客发布,了解有关 Silverlight 的更多讨论以及为何引导您使用异步服务调用。引用博客文章中的内容:“插件架构仅允许异步请求的全部目的是让插件无法锁定浏览器”。
Eric Lippert 对后台工作占用 UI 线程的问题给出了很好的解释/讨论 在这篇 MSDN 杂志文章中,介绍了即将推出的异步等待模式。绝对值得一读。
这里要记住的主要事情是,无论后台可能发生多少有用的工作,如果 UI 没有响应,则对于用户而言,应用程序什么也不做。在 Silverlight 中使用异步 WCF 服务调用允许您在等待结果的同时对 UI 执行其他操作,而不是让用户想知道为什么他们不能执行任何操作。
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 不允许对服务进行非异步调用。当您编写 Silverlight 访问 WCF 服务的代码时,请考虑异步。
Silverlight doesn't allow non-asynchronous calls to services. When you code Silverlight access to WCF services, think Asynchronous.