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

发布于 2024-11-16 17:22:50 字数 445 浏览 0 评论 0原文

自上周以来我一直在尝试用谷歌搜索答案,但没有找到任何东西。也许我只是用不正确的关键字进行搜索...

基本上,我们有一个正在运行的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱她像谁 2024-11-23 17:22:50

假设您询问如何在单独的 DLL/应用程序中运行的服务中实现在一个 DLL 中声明的服务契约:

编辑以匹配后期编辑

  1. 将带有服务契约的 DLL 引用添加到包含服务的应用程序
  2. 在具有服务实现的 .cs 文件中,为服务契约的命名空间添加一条 using 语句,
  3. 从服务契约派生服务(如果将服务契约定义为具体类而不是接口,并且您想要公开您的多个合约服务
  4. 如果自托管,则创建一个 ServiceHost,传递另一个程序集中服务的类型对象,如果 IIS 托管,则创建一个 .svc 文件,引用另一个程序集中的类作为服务
  5. 在配置文件中添加一个服务元素,命名完全限定的服务元素服务名称
  6. 在新合约的唯一地址处向服务添加端点

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

  1. add a reference to the DLL with the service contract to the application containing the service
  2. In the .cs file with service implmentation add a using statement for the namespace of the service contract
  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
  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
像极了他 2024-11-23 17:22:50

当您将其他程序集 (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).

瑾兮 2024-11-23 17:22:50

我想一种解决方法是您有一个主 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文