开发者

How to unhide Silverlight WCF BeginXXXX and EndXXXX service calls

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)

See entire blog post here

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.


You will find there is an interface that simply has the name Service1 and that the Service1Client 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:-

 Service1 scClient = new Service1Client();

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜