有没有办法通过单个端点公开多个 WCF 服务?

发布于 2024-08-25 10:02:53 字数 147 浏览 4 评论 0原文

我目前通过 WCF 提供多种方法的服务。我想进行重构,以便将单个服务分为多个类,每个类提供一组不同的功能。但是,我希望仍然与客户端保持单一连接。这可能吗?

我想答案是否定的,那么我该如何解决这个问题呢?有解决方法吗?或者我的想法完全愚蠢,我应该改变应用程序的设计?

I currently offer a service with many methods via WCF. I'd like to refactor so the single service is split into multiple classes, each offering a different set of functionality. However, I'd prefer to still have a single connection to the client. Is this possible?

I guess the answer is No, so how should I solve this issue? Is there a workaround? Or is my idea completely stupid and I should change the design of the application?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

幽蝶幻影 2024-09-01 10:02:53

请记住 E = ABC(端点 = 地址、绑定、合约)。使用不同的合同,即使其他条件相同,您仍然会得到不同的端点。

但是,单个服务可以实现多个服务契约。这将允许单个 .svc 文件成为多个不同服务合同的目标,所有服务合同都配置为相对于 .svc 的 URL。

Remember E = ABC (Endpoint = Address, Binding, Contract). With a different contract, even with all else equal, you've still got a different endpoint.

However, a single service can implement multiple service contracts. This would allow a single .svc file to be the target of several different service contracts, all configured as URLs relative to the .svc.

物价感观 2024-09-01 10:02:53

您可以实现部分类,它允许您将内容分离到各个 cs 文件中,同时维护单个接口和端点。这不是最理想的方式,因为最终它仍然是由部分类组成的单个类,但至少它在文件结构中看起来像它,从而提供了一些分离而不是一个巨大的类文件。

示例结构:

IMyService.cs

[ServiceContract]
public interface IMyService
{
   [OperationContract]
   string GenericMethod()

   [OperationContract]
   string GetUsers(int companyId)

   [OperationContract]
   string GetMessages(int userId)

}

MyService.cs

//Put any attributes for your service in this class file
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public partial class MyService : IMyService
{
  public string GenericMethod() 
  {
     return "";
  }
}

UserService.cs

public partial class MyService
{
    public string GetUsers(int companyId) 
    {
       return "";
    }
}

MessagingService.cs

public partial class MyService
{
      public string GetMessages(int userId) 
      {
          return "";
      }
}

You could implement partial classes that allow you to separate your content in individual cs files while maintaing a single interface and endpoint. This isn't the most ideal way, because at the end of the day it is still a single class made up of partial classes, but at least it looks like it in your file structure, thus giving some separation rather than a massive class file.

Example Structure:

IMyService.cs

[ServiceContract]
public interface IMyService
{
   [OperationContract]
   string GenericMethod()

   [OperationContract]
   string GetUsers(int companyId)

   [OperationContract]
   string GetMessages(int userId)

}

MyService.cs

//Put any attributes for your service in this class file
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public partial class MyService : IMyService
{
  public string GenericMethod() 
  {
     return "";
  }
}

UserService.cs

public partial class MyService
{
    public string GetUsers(int companyId) 
    {
       return "";
    }
}

MessagingService.cs

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