Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4024750
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:45:37+00:00 2026-05-20T10:45:37+00:00

Can I have a single service with multiple endpoints and multiple contracts using generics.

  • 0

Can I have a single service with multiple endpoints and multiple contracts using generics. I am running into an issue where the metadata cannot be created (It hink it may just be a config issue and not sure what my base host address would need to look like):

    namespace WCFSingleService
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
        [ServiceContract]
        public interface ISingleService<T>
        {
            [OperationContract]
            T GetData(T item);

         }   

    }

namespace WCFSingleService
{
    [ServiceContract(Name = "User")]
    public interface IUserSingleService: ISingleService<User>
    {
    }
}

namespace WCFSingleService
{
    [ServiceContract(Name = "Some")]
    public interface ISomeSingleService: ISingleService<Some>
    {
    }
}

public partial class SingleService : IUserSingleService
    {
        public User GetData(User item)
        {
            //Do something
        }



    }

public partial class SingleService : ISomeSingleService
    {
        public Some GetData(Some item)
        {
            //Do something
        }



    }

Is this possible and what would the configuration for this service look like? Also, would I be able to consume the service from, say, an AJAX client? I guess I would since I am not trying to pass in a type to the contract and each contract would have its own endpoint, right? Thanks!

Here is my current configuration:

<system.serviceModel>
    <services>
      <service name="WCFSingleService.SingleService" behaviorConfiguration="WCFSingleService.ServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8732/Design_Time_Addresses/WCFSingleService/SingleService" />            
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="User" binding="wsHttpBinding" contract="WCFSingleService.IUserSingleService"/>
        <endpoint address="Some" binding="wsHttpBinding" contract="WCFSingleService.ISomeSingleService"/>




        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> 
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WCFSingleService.ServiceBehavior">
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

UPDATE:
Well, I was tring to figure out why my servcie wasn;t wroking, once I turned debugging on, that opened up the error dorr. DUH! Anyway, the issue I was having had to do with the same method name being created for both services. So, does anyone know of a way to have WCF rename the method names if multiple services impelement the same interface? Is there a decoration I can put on a method inside one of the implementations to make it appear different?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:45:38+00:00Added an answer on May 20, 2026 at 10:45 am

    I figured out pretty much what I wanted to accomplish. Basically, I could still setup my code to use generics while having one service. I got the idea for the single service here. I then realized that I needed to specify the ServiceContract on the partial class SingleService (Not the interfaces themselves) and decorate my implemented methods with the OperationContract(Name=”TheExposedNameOfTheMethod”). Here is some of the code:

    public interface ISingleService<T>
        {
            //[OperationContract]
            T GetData(T item);
    
    
        }
    
    
    public interface IUserSingleService: ISingleService<User>
        {
        }
    
    public interface IOtherSingleService: ISingleService<Other>
        {
        }
    
    [ServiceContract]
        public partial class SingleService : IUserSingleService
        {
            [OperationContract(Name = "GetDataUser")]
            public User GetData(User item)
            {
                switch(item.MessageCommand)
                {
                    case "Create":
                        //do stuff to for a User create
                        break;
                    case "Update":
                        //do stuff to for a User update
                        break;
                    case "Delete":
                        //do stuff to for a User Delete
                        break;
                }
    
                return item;
    
            }
    
    
    
        }
    
    //You only need to specifc the ServiceContract attribute in one of the partial classes
            public partial class SingleService : IOtherSingleService
        {
            [OperationContract(Name = "GetDataOther")]
            public Other GetData(Other item)
            {
                ...do something
                return item;
    
            }
    
    
    
        }
    

    Here is what the endpoint would look like:

    <endpoint  binding="basicHttpBinding" name="TheService"
              contract="SingleService" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A single Biztalk Server can have multiple Host processes. Is it possible to create
I have several somewhat separate programs, that conceptually can fit into a single project.
I have a WCF service (the same one) running on multiple servers, and I'd
Can a single WCF Service endpoint be set up to authenticate against multiple Authentication
I have a single service installer project that installs multiple services. This is great
I have several service contracts exposed over WCF, which use multiple datacontracts. The service
I am running into a peculiar issue with an app which has multiple Activities.
Is there a way I can have multiple ssl certificates point to a single
I have a single RoutedUICommand that can be accessed through various places in the
I have a method that can return either a single object or a collection

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.