如何取消隐藏 Silverlight WCF BeginXXXX 和 EndXXXX 服务调用
我一直在学习 RX 和 Silverlight,并发现一篇博客文章展示了如何在 Rx 中使用 Observable.FromAsyncPattern 实现 silverlight wcf 服务。在博客文章中,它有一个给 Silverlight 开发人员的说明...
Silverlight 的重要说明!
Silverlight 的 Web 服务生成的客户端代码做了一些事情 烦人 - 它隐藏了 BeginXXXX/EndXXXX 调用,大概是为了 使 Intellisense 更干净。然而,它们并没有消失,就像你一样 可以通过将 MyCoolServiceClient 对象强制转换为其 底层接口(即LanguageServiceClient对象有一个 生成的 ILanguageServiceClient 接口并实现)
我不确定他说的是什么意思您需要将 ServiceClient 强制转换为接口。
如果我生成了 Service1Client 的实例,例如
Service1Client scClient = new Service1Client();
我将如何投射它?我已经尝试过...
((IService1Client) scClient)
但没有效果...非常感谢任何建议。
I have been learning about RX and Silverlight and found a blog post showing how to implement a silverlight wcf service using the Observable.FromAsyncPattern in Rx. In the blog post it has a note to Silverlight developers...
An important note for Silverlight!
Silverlight’s web service generated client code does something a bit
annoying – it hides away the BeginXXXX/EndXXXX calls, presumably to
make the Intellisense cleaner. However, they’re not gone, the way you
can get them back is by casting the MyCoolServiceClient object to its
underlying interface (i.e. the LanguageServiceClient object has a
generated ILanguageServiceClient interface that it implements)
While I can see that the BeginXXX and EndXXX methods are definitely hidden for my service, I am unsure of what he means when he says that you need to cast the ServiceClient to the interface.
If I have generated an instace of the Service1Client e.g.
Service1Client scClient = new Service1Client();
How would I cast it? I have tried...
((IService1Client) scClient)
But to no avail... any suggestions much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您会发现有一个名为
Service1
的接口,并且Service1Client
实现了该接口。是的,我知道这很奇怪,但没有语法规则规定所有接口类型都以字母“I”开头。因此,将您的代码更改为:-然后使用具有更简单的开始/结束异步模式的
Service1
。请小心,因为传递给 Begin 的回调不会在 UI 线程上执行。You will find there is an interface that simply has the name
Service1
and that theService1Client
implements that interface. Yes I know thats weird but there is no syntax rule that states that all interface types begin with the letter "I". So change your code to:-Then work with
Service1
which has the simpler Begin/End async pattern. Just be careful because the callback passed to Begin will not be executed on the UI thread.这意味着生成的代码包含显式实现< /a> 接口。这样做的原因有很多;我不确定这里的架构考虑因素是什么,因为我从未做过你正在做的事情。
您应该检查您的
Service1Client
以查看它是否实现了包含这些 Begin/End 方法的生成接口。如果是,则就是您必须将服务客户端类型转换为的接口。如果不是,也许自一年前以来情况已经发生了变化。It means that the generated code includes types that explicitly implement interfaces. There are many reasons for doing this; I'm not sure what the architectural considerations are here, as I have never done what you are doing.
You should inspect your
Service1Client
to see if it implements a generated interface that contains these Begin/End methods. If it does, that is the interface you must cast the service client type to. If not, perhaps things have changed since a year ago.