简体   繁体   中英

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 interfaces (ServiceContracts) and data definitions (DataContracts).
What I need : runtime generated/created WCF client proxy.

Have some solutions?

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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM