简体   繁体   English

将WCF合同移动到单独的dll

[英]Moving WCF contracts to a separate dll

I want to move WCF contracts interfaces to third DLL and start consuming them from clients when I am generating proxy by hand. 我想将WCF契约接口移动到第三个DLL,并在我手动生成代理时开始从客户端使用它们。

Do those interfaces in the DLL have to have the [ServiceContract] attribute when I consume them from the client to generate a proxy ? 当我从客户端使用它们生成代理时,DLL中的那些接口是否必须具有[ServiceContract]属性?

Any idea what is the best naming for Dll that will have only contracts and the DTOs to share between client and the server. 知道什么是Dll的最佳命名,只有合同和DTO在客户端和服务器之间共享。

It is very common practice to put WCF data and service contract to separate assembly. 将WCF数据和服务契约放在单独的程序集中是很常见的做法。 In my previous project we used naming like Company.OurProject.Contracts.dll . 在我之前的项目中,我们使用了像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. 我认为要生成具有重用现有类的代理,您应该将服务契约的接口(标有[ServiceContractAttribute] )和相应的数据契约放到该程序集中。 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 以下是关于SO的另一个很好的答案,更深入地了解当选择“重用引用程序集中的类型”时可以重用的内容: WCF服务引用生成自己的契约接口,不会重用我的

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. 是的,您应该将服务合同放在合同dll中的服务接口上。

Keep in mind that the namespace does not have to match the name of the dll. 请记住,命名空间不必与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 . 假设您当前的程序集类似于CompanyName.Technology.Service.dll ,其名称空间如CompanyName.Technology.Service您应该将合同提取到另一个程序集但是保持命名空间相同(提供它仍然有意义)并且具有CompanyName.Technology.Service.Contracts程序集名称。 What you do not want to have is a namespace with the name "contracts" in it. 你不想拥有的是一个名为“contracts”的命名空间。

I use *.ServiceContracts.dll because I end up having multiple contract assemblies in my systems. 我使用* .ServiceContracts.dll,因为我最终在我的系统中有多个合同程序集。 DataContracts.dll for example is used for accessing data stores. 例如,DataContracts.dll用于访问数据存储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM