简体   繁体   English

WCF-来自另一个程序集的服务合同

[英]WCF - Service Contract from another assembly

I have tried googling for an answer since last week and haven't found anything. 自上周以来,我一直尝试使用Google搜索来寻找答案,但没有发现任何问题。 Maybe I'm just searching with incorrect key words... 也许我只是在搜索不正确的关键字...

Basically, we have a running WCF service and then we have a separate dll with another ServiceContract in it. 基本上,我们有一个正在运行的WCF服务,然后有一个单独的dll,其中包含另一个ServiceContract。 We want to know if it is possible to expose the separate dll in the current running service and if one can, how? 我们想知道是否有可能在当前正在运行的服务中公开单独的dll,如果可以,如何?

We are still new to WCF, so please excuse if this is a stupid question. 我们仍然是WCF的新手,所以如果这是一个愚蠢的问题,请原谅。 :( :(

We are working with .NET 3.5 SP1 and C#. 我们正在使用.NET 3.5 SP1和C#。

Regards 问候

EDIT: We want to separate our service into "modules". 编辑:我们想将我们的服务分为“模块”。 So the service implementations (Methods, ect) and contracts (Interfaces) are all in separate libraries. 因此,服务实现(方法等)和合同(接口)都在单独的库中。 So lets say you have a module called "Clients". 假设您有一个名为“客户”的模块。 We want everything related to Clients to be in the same separate library (DLL) instead of one big base class that inherits from multiple interfaces. 我们希望与客户端相关的所有内容都在同一个单独的库(DLL)中,而不是从多个接口继承的一个大型基类。 This is a huge service and we need multiple developers to work on different sections of the same service at the same time. 这是一项巨大的服务,我们需要多个开发人员同时处理同一服务的不同部分。 This is what I've been instructed to figure out, but if it can be done then it can't. 这是我被指示要弄清楚的,但是如果可以做到,那么就不可能。 I hope this makes more sens?? 我希望这能带来更多的感觉?

Assuming you are asking how you can implement a service contract declared in one DLL in a service running in a separate DLL/Application: 假设您在问如何在单独的DLL /应用程序中运行的服务中实现在一个DLL中声明的服务协定:

Edits to match post edits 编辑以匹配帖子编辑

  1. add a reference to the DLL with the service contract to the application containing the service 将对带有服务合同的DLL的引用添加到包含该服务的应用程序中
  2. In the .cs file with service implmentation add a using statement for the namespace of the service contract 在具有服务实现的.cs文件中,为服务协定的名称空间添加using语句
  3. derive the service from the service contract (you will have problems if you define your service contracts as concrete classes rather than interfaces and you want to expose multiple contracts on your service 从服务合同派生服务(如果将服务合同定义为具体的类而不是接口,并且要在服务上公开多个合同,则会遇到问题
  4. If self hosting then create a ServiceHost passing the type object of the service in the other assembly, if IIS hosting create an .svc file referencing the class in the other assembly as the service 如果是自托管,则创建一个ServiceHost,在另一个程序集中传递服务的类型对象;如果IIS托管,则创建一个.svc文件,将另一个程序集中的类引用为服务。
  5. Add a service element in the config file naming the fully qualified name of the service 在配置文件中添加服务元素,以命名服务的标准名称
  6. Add an endpoint to the service at a unique address for the new contract 在新合同的唯一地址处将端点添加到服务

When you take the other assembly (dll) as a reference in the "main" project, then add a using directive to the file where the WCF service is instantiated. 当您将另一个程序集(dll)作为“主”项目中的引用时,然后将一个using指令添加到实例化WCF服务的文件中。 Then you can simply use the referenced service contract to set up a running service with the right endpoints and binding(configuration). 然后,您可以简单地使用引用的服务合同来设置具有正确端点和绑定(配置)的运行服务。

I guess one work around is you have a main ServiceHost hosting your WCFMainLib and then all your clients will connect to WCFMainLib. 我想一种解决方法是,您有一个主ServiceHost托管WCFMainLib,然后所有客户端都将连接到WCFMainLib。

WCFMainLib then acts like a proxy to connect to all other WCFModuleLib on localhost (or other servers) to fetch data. 然后WCFMainLib就像代理一样,连接到本地主机(或其他服务器)上的所有其他WCFModuleLib以获取数据。

WCFMainlib will implement the IWCFModuleLib1, IWCFModuleLib2 etc service contract interfaces and expose them to the WCFClient. WCFMainlib将实现IWCFModuleLib1,IWCFModuleLib2等服务协定接口,并将其公开给WCFClient。 Actual implementation of interfaces will then be a call to the actual WCFModuleLibs. 接口的实际实现将成为对实际WCFModuleLibs的调用。

This may introduce some overhead, but overall also introduces several "features" that may benefit your boss or service availability. 这可能会带来一些开销,但总体上还会引入一些可能有助于老板或服务可用性的“功能”。

OR, if you are just wanting to delegate programming work, maybe you can tell each team to work with partial classes for your WCFLib with each service contract on a partial class then do a nightly compile. 或者,如果您只是想委托编程工作,也许您可​​以告诉每个团队使用WCFLib的部分类,并在部分类上使用每个服务合同,然后每晚进行编译。

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

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