views:

169

answers:

4

I have a Client website, a WCF service and a library of domain objects (.cproj).

I want the client to use my library of domain objects directly, not the proxy generated version of the domain objects. Is there a simple way of doing this?

A: 

Include the library project or DLL in your client project rather than creating a service reference. You can generate the service reference to create all the necessary WCF configurations to call the service, but just don't use the generated proxy or datatypes (e.g. the code in Reference.cs) - use the types in the included DLL directly. You may need to write a client yourself, but this is simple, and can be basically copied from the generated client in a service reference.

That said, sharing the datatypes directly between the client and service sort of breaks service-oriented architecture patterns. Now both your client and service are dependent on the same DLL, rather than the client just being dependent on a service.

Andy White
+1  A: 

There are some gotchas in this. I saw this video from Miguel Castro (uber cool dude) about doing the WCF right way. This might give you a whole lot of insight.

Miguel Castro - Extreme WCF

Perpetualcoder
+2  A: 

Include a reference to the dll in your client project. Then add a Service Reference. When you add the service reference there is an option to use the types in the dll and not create them in the references.cs.

Shiraz Bhaiji
A: 

Anyone ... why the svcutil serializes a structure which I dont use in servce contract and which is the attributes type within a class that is a part of the contract? The class definition and attribute definition are not in the same assemblies, so I'm just adding reference to the library where the class is defined. If I add a reference to the library where the structure is defined - the service reference does not contain serialization of a structure anymore. Can I achive that somehow without adding an additional reference in some other way? (e.g. with some attribute over the class)

Gru