views:

1722

answers:

3

Say I have the following interface that I want to share between my server (a regular web service) and my client (a silverlight 2.0 application):

public interface ICustomerService
{
    Customer GetCustomer(string name);
}

My web service implements this interface, and references a class library where Customer type is defined.

Usually, if you want to consume this service from a WCF client, say a winforms app, you could share your model assembly and your service contract interfaces. Then, by using a ChannelFactory, you can dynamically create a proxy which implements your service interface. Something like:

ICustomerService myService = new ChannelFactory<ICustomerService>(myBinding, myEndpoint);
Customer customer = myService.GetCustomer("romain");

I basically want to do the same thing, but from a Silverlight 2.0 application. The silverlight ChannelFactory doesn't seems to act like the other one...

Do you know if it's possible ?

Note : Since a Silverlight application can only refers Silverlight projects, I have:

Two versions of MyModel.dll which contains Customer type:

  • One compiled targetting .NET framework 3.5, referenced by my web service project
  • Another compiled targetting the silverlight 2.0 framework, referenced by my silverlight app

Two versions of MyServicesContracts.dll which contains ICustomerService interface:

  • One compiled targetting .NET framework 3.5, referenced by my web service project
  • Another compiled targetting the silverlight 2.0 framework, referenced by my silverlight app
+3  A: 

I think you will find this thread interesting. You can share code files between separate projects or compile a single project against multiple targets.

Cristian Libardo
A: 

I could be wrong, but I think if you decorate objects being returned by your WCF Service with the DataContract and DataMember attributes, you should be able to share objects between your Silverlight application and WCF service without creating the class in your client (should be handled by the proxy.

Steven Murawski
A: 

Very short...


You can have your proxies created under the silverlight application adding a service reference to your service. When you do this, you'll have your proxies automaticaly generated on the client.


Your wcf services interfaces must be anotated with DataContract and OperationContract attributes and the POCO classes used with this services must have DataContract and DataMember attributes.


http://msdn.microsoft.com/en-us/library/cc197940(VS.95).aspx