Wednesday, January 28, 2009

WCF in the Real World - a case of two definitions for a class

I've been using 2 WCF web services on my project - Service1.svc returns an entity object which I have to pass to Service2.svc. Now, after I add a service reference to both in Visual Studio, I get 2 classes - Service1.Entity and Service2.Entity and I can't cast one to the other.

The solution is to either take the properties of one class and put it into another within the client-side code, or put the class into a class library used at both the server and the client side. At the client side, you simply have to add a reference to the DLL before you add the service reference to prevent svcutil from creating the class in a new namespace.

UPDATE: You can find more about it here and here.

No comments: