views:

812

answers:

3

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?

A: 

Take a look at the WCF Dynamic Proxy Sample Project

Mel Gerats
Thanks.I already had a look at this, but this is not easy to port to Silverlight. I'm looking for a Silverlight-ready solution... If there is any at the moment :)
fredlegrain
A: 

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! :)

fredlegrain
A: 

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");
erxuan
As he said, this is "the .NET version of". Silverlight do only support async service calls and most services do not provide interface for async calls (and IMO they should'nt). Starting at that point, things go lot more tricky.
fredlegrain
What I expect is something more like what K.Kozmic does in .Net : see http://kozmic.pl/archive/2009/08/09/making-asynchronous-wcf-calls-without-svcutil.aspx
fredlegrain