This question follows upon someone else's question because the asker never accepted or said the solution to his problem, if he found one.
What's the most portable way to make a Si开发者_开发百科lverlight & Regular .NET REST client
If you're familiar with WebChannelFactory from .NET, it provides a clean way to create a client to access WCF Web Http (REST) services. There is no such class in Silverlight 4, so it might be worth creating a class that acts like it.
How would you get started in creating such as class, that creates a client that implements your service's contract (TChannel)? I don't know how Microsoft did this, but it looks like they somehow create a new Type at runtime to implement the interface. Would you approach doing this in Silverilght? Maybe by looking at System.Reflection.Emit and TypeBuilder.AddInterfaceImplementation?
A more specific-to-System.Reflection.Emit question I have is, what's the simplest way to use MethodBuilder to create a method for your TypeBuilder, if you want to use existing compiled code? It looks like you could use MethodBuilder.CreateMethodBody, however, in Silverlight 4 this does not exist.
First of all WebChannelFactory
is not a clean way to build REST client - that is completely RESTless approach because it requires you to share all contracts between service and client. WebChannelFactory
exists to provide compatibility with standard WCF service clients and somehow (wrongly) simplify calling REST services written in .NET. That is also the answer how MS did it - there is no runtime creation of the type. Types are defined at design time.
That's a nice article. I decided to create a class which simplifies calling REST WCF services and more closely meets my needs. Maybe others will find it useful.
WebHttpClient
精彩评论