Solutions for dynamic WCF client proxy in Silverlight?
I currently need to access WCF services from within Silverlight (3.0) application, but I need it dynamic.
What I have access to : the service inter开发者_JAVA百科faces (ServiceContracts) and data definitions (DataContracts). What I need : runtime generated/created WCF client proxy.Have some solutions?
Take a look at the WCF Dynamic Proxy Sample Project
I found this "old" post (September 16, 2008).
But I could not make it run properly under Silverlight 3.0 (didn't try with previous versions of Silverlight).
WorkSight Blog » Blog Archive » A Dynamic WCF Client Proxy in Silverlight
Let us know if any of you manages to make it work! :)
My understanding is if you follow the procedure of client access described in Understanding WCF Services In Silverlight 2, you should be able to choose which service to access at runtime, because you don't need to create proxy at client side.
A snippet from this article:
Now we may turn our attention to the client application. To begin, let me start off by reminding everyone that you shouldn't ever use "Add Service Reference" in Visual Studio for magical service client creation. The code is incredibly verbose, hard to manageable, edits are prone to being overwritten, and it's almost always used as an excuse to not actually learn WCF.
As I've mentioned many times already, WCF relies on the concept of the ABC. For both .NET and Silverlight, you merge an address and a binding with a contract in a channel factory to create a channel. This isn't just fancy conceptual architect speak, this is exactly what your code would look like (the sign of really good architecture!) Below is the .NET version of what I mean:
BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
EndpointAddress endpointAddress = new EndpointAddress("http://localhost:1003/Person.svc");
IPersonService personService = new ChannelFactory<IPersonService>(basicHttpBinding, endpointAddress).CreateChannel();
Person person = personService.GetPersonData("F488D20B-FC27-4631-9FB9-83AF616AB5A6");
精彩评论