WCF service that supports a common C # class that implements a common interface

I have a WCF service that provides a common interface (and the service has a common class that implements this interface).

Then I try to host this service in a managed console application (for testing purposes only right now). String ThreadStart leads to the fact that the type of the expression type T is not found.

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

My question is how to handle this case as a whole?

    // 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 a Service Class

  [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);
       }
}

The client will use it as if you were using some common type:

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

EDIT2: @asawyer point , Main , , ? . , , : INIT (Type typeOfBST). , , int, BST. , , BST.

?

+3
2

. . , . , , , ( WSDL).

WCF , , , , - . . - , - - T.

, , , ( , ).

Edit:

: . , . , URL- . , . URL- .

- WCF, .

, , . , , , , . - KnownType DataContractResolver .

+5

, ,

interface ITest { }
class Test<T> where T : ITest { }

:

var test = new Test<T>();

T , :

class ImplementsITest : ITest { }

var test = new Test<ImplementsITest>();

Main()

static void Main(string[] args)
{
   new Thread(new ThreadStart(StartBSTService<SomeTypeThatActuallyExists>)).Start();
}

BSTService ? , .

+1

All Articles