mafu
mafu

Reputation: 32650

Is there a way to expose multiple WCF services through a single endpoint?

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?

Upvotes: 6

Views: 839

Answers (2)

Gaff
Gaff

Reputation: 5657

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 "";
      }
}

Upvotes: 0

John Saunders
John Saunders

Reputation: 161773

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.

Upvotes: 4

Related Questions