WCF - 来自另一个程序集的服务合同
自上周以来我一直在尝试用谷歌搜索答案,但没有找到任何东西。也许我只是用不正确的关键字进行搜索...
基本上,我们有一个正在运行的 WCF 服务,然后我们有一个单独的 dll,其中包含另一个 ServiceContract。我们想知道是否可以在当前运行的服务中公开单独的 dll,如果可以,如何实现?
我们对 WCF 还很陌生,所以如果这是一个愚蠢的问题,请原谅。 :(
我们正在使用 .NET 3.5 SP1 和 C#。
问候
编辑: 我们希望将我们的服务分成“模块”。因此,服务实现(方法等)和契约(接口)都位于单独的库中。假设您有一个名为“客户端”的模块。我们希望与客户端相关的所有内容都位于同一个单独的库(DLL)中,而不是一个继承多个接口的大基类。这是一项庞大的服务,我们需要多个开发人员同时处理同一服务的不同部分。这是我被指示要弄清楚的,但如果可以做到,那就不能做到。我希望这更有意义?
I have tried googling for an answer since last week and haven't found anything. 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. We want to know if it is possible to expose the separate dll in the current running service and if one can, how?
We are still new to WCF, so please excuse if this is a stupid question. :(
We are working with .NET 3.5 SP1 and 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. 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??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设您询问如何在单独的 DLL/应用程序中运行的服务中实现在一个 DLL 中声明的服务契约:
编辑以匹配后期编辑
Assuming you are asking how you can implement a service contract declared in one DLL in a service running in a separate DLL/Application:
Edits to match post edits
当您将其他程序集 (dll) 作为“主”项目中的引用时,然后将 using 指令添加到实例化 WCF 服务的文件中。然后,您可以简单地使用引用的服务契约来设置具有正确端点和绑定(配置)的正在运行的服务。
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. Then you can simply use the referenced service contract to set up a running service with the right endpoints and binding(configuration).
我想一种解决方法是您有一个主 ServiceHost 托管您的 WCFMainLib,然后您的所有客户端都将连接到 WCFMainLib。
然后,WCFMainLib 充当代理,连接到本地主机(或其他服务器)上的所有其他 WCFModuleLib 以获取数据。
WCFMainlib 将实现 IWCFModuleLib1、IWCFModuleLib2 等服务契约接口并将它们公开给 WCFClient。接口的实际实现将是对实际 WCFModuleLib 的调用。
这可能会带来一些开销,但总体而言还引入了一些可能有利于您的老板或服务可用性的“功能”。
或者,如果您只是想委派编程工作,也许您可以告诉每个团队使用 WCFLib 的部分类,并在部分类上使用每个服务契约,然后进行夜间编译。
I guess one work around is you have a main ServiceHost hosting your WCFMainLib and then all your clients will connect to WCFMainLib.
WCFMainLib then acts like a proxy to connect to all other WCFModuleLib on localhost (or other servers) to fetch data.
WCFMainlib will implement the IWCFModuleLib1, IWCFModuleLib2 etc service contract interfaces and expose them to the WCFClient. Actual implementation of interfaces will then be a call to the actual 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.