Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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 "";
      }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top