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

  • SEARCH
  • Home
  • 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 5995695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:59:48+00:00 2026-05-22T23:59:48+00:00

I have a WCF service which exposes a Generic interface (and the service has

  • 0

I have a WCF service which exposes a Generic interface (and the service has a generic class implementing this interface).

Then i try to host this service in a managed console app (just for testing purposes right now). The ThreadStart line results in error saying type for T not found.

Now i cannot make Main generic by doing Main< T >(string[] args) where T: IComparable< T > because then it says, Main entry point not found.

My question is how to handle this case in general ?

    // Service Hosting app
    static void Main(string[] args)
    {
       new Thread(new ThreadStart(StartBSTService<T>)).Start();
    }

    static void StartBSTService<T>() where T : IComparable<T>
    {
        string baseAddress = "http://localhost:8080/bst";

        StartAService(typeof(BSTService<T>), baseAddress);
    }

EDIT: Adding the Service class as well

  [ServiceContract(Namespace = "http://Microsoft.Samples.GettingStarted")]
  public interface IBSTService<T> where T : IComparable<T> //: ICollection<T>
  {
      [OperationContract]
      void Add(T toAdd);
      // For brevity, not providing all other methods
      // but they are similar IColleciton methods.
  }

public class BSTService<T> : IBSTService<T> where T : IComparable<T>
{
       BinarySearchTree<T> tree = new BinarySearchTree<T>();

       public void Add(T toAdd)
       {
           tree.Add(toAdd);
       }
}

Client will use it like you will use any generic type:

    BSTService<string> client = new BSTService<string>; 
    // OR
    BSTService<int> client = new BSTService<int>;

EDIT2:
@asawyer’s point seems logical, that Main is consumer of generic class, so it should provide the type, but then do i have to start a new endpoint for every type ? and how to handle that. Like i can write a service wrapper which exposes only one method say INIT(Type typeOfBST). client calls this to tell the service that he wants to initiate either int or string BST. and then client calls the real methods with given type and the service channels those calls to different endpoints each of which is exposing a differently typed BST.

How to handle such cases in general ?

  • 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-22T23:59:49+00:00Added an answer on May 22, 2026 at 11:59 pm

    When you host the service you cannot use open generics. You must specify concrete type to host concrete service. If you want to host services for more generic arguments you must indeed create a new host for each argument type and expose an endpoint with an unique address for each of them. Once the service is hosted it must be able to say what types it accepts and describe them in the service description (source for WSDL).

    WCF works on basis where you host the service which must be able to describe messages it accepts – because of that it generates service description. Service is able to serialize messages according to the description. Any client on any platform can use the description and send the correct message to the service – client will know about allowed content of the message from the description and because of that service host must use the concrete type – not T.

    You can overcome this by specifying base type as generic argument but even after that your service must know about all derived types which can be used instead of the base type (there are multiple techniques for this but none of them offer random type).

    Edit:

    Technically what you ask for means: send the name of the type from the client to the main service. The main service will check if the service with the type already exists. If yes it will send the url of the service back to the client. If not it will creates the service via reflection and starts it. It will store information about new hosted service and sends the url back to the client.

    Another variant is starting all services upfront and having single WCF Routing service which will route request to correct service.

    Such solutions look like maintenance nightmare and the first one will have much worse performance because two network calls will be needed for each operation. Also it is not generally interoperable because your clients will have to get generic contract upfront to be able to call such services. Simply don’t do it – define finite set of used classes and use KnownType or DataContractResolver with single service.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a WCF service which has a method returning object Person.
I have a WCF Web Service which is referenced from a class library. After
I have a WCF service which exposes a method that returns an array of
I have a WCF service which has two methods exposed: Note: The wcf service
I have a plugin that exposes a wcf service. if I test this service
I have written a simple WCF web service which is configured programmaticaly. It exposes
I have a windows service that exposes a TCP connection (using WCF). This service
I have a WCF Service which exposes an endpoint using the webHttpBinding and is
I have a WCF service that exposes 1 method GetNextObjectInList(int id) which hits a
I have a WCF service which will be hosted under IIS. Now I have

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.