4

I want to move WCF contracts interfaces to third DLL and start consuming them from clients when I am generating proxy by hand.

Do those interfaces in the DLL have to have the [ServiceContract] attribute when I consume them from the client to generate a proxy ?

Any idea what is the best naming for Dll that will have only contracts and the DTOs to share between client and the server.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Night Walker
  • 20,638
  • 52
  • 151
  • 228
  • What do you mean by "generating proxy by hand"? As I understood you want to generate proxy by reusing classes from existing assembly. Is that the case? – Andriy Buday May 13 '12 at 22:34

3 Answers3

5

It is very common practice to put WCF data and service contract to separate assembly. In my previous project we used naming like Company.OurProject.Contracts.dll. I think that to generate proxy with reusing existing classes you should put your interfaces for service contracts (those marked with [ServiceContractAttribute]) and corresponding data contracts to that assembly. I would avoid putting there actual implementation of the services.

Here is another great answer on SO with more insight into what can be reused when "Reuse types in referenced assemblies" is selected: WCF Service Reference generates its own contract interface, won't reuse mine

Community
  • 1
  • 1
Andriy Buday
  • 1,959
  • 1
  • 17
  • 40
1

This is common and perhaps recommended approach.

Yes you should put the service contract on the service interface which will live in the contract dll.

Keep in mind that the namespace does not have to match the name of the dll. Assuming that your current assembly is something like CompanyName.Technology.Service.dll with a namespace like CompanyName.Technology.Service you should extract out the contract to another assembly BUT keep the namespace the same (providing it still makes sense to) and have an assembly name of CompanyName.Technology.Service.Contracts. What you do not want to have is a namespace with the name "contracts" in it.

Bronumski
  • 14,009
  • 6
  • 49
  • 77
  • Why is it important to keep the namespace and not have the name "contracts" in it? For backward compatibility? – xr280xr Dec 17 '13 at 22:22
  • 1
    @xr280xr - The point I was making was by moving it to another assembly you do not want to change the namespace if you are not setting a custom namespace in the ServiceContract attribute. This would cause a contract mismatch between any existing clients. – Bronumski Dec 18 '13 at 00:08
0

I use *.ServiceContracts.dll because I end up having multiple contract assemblies in my systems. DataContracts.dll for example is used for accessing data stores.

Rory Primrose
  • 633
  • 4
  • 10
  • Also, I would avoid the generated proxy if you are sharing your binaries. I find it a much cleaner way of working with WCF. You can get down to using the proxy directly rather than generated code that wraps the proxy. – Rory Primrose May 14 '12 at 00:18