Moving WCF contracts to a separate dll

后端 未结 3 1690
情话喂你
情话喂你 2021-01-06 09:58

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

相关标签:
3条回答
  • 2021-01-06 10:12

    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

    0 讨论(0)
  • 2021-01-06 10:17

    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.

    0 讨论(0)
  • 2021-01-06 10:31

    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.

    0 讨论(0)
提交回复
热议问题