WCF service with shared service class and contract?

Consider the following very simple piece of code that implements a web service that simply drives away whatever (string) object the client sends to it:

namespace ServiceExample
{
    //------ Generic service and interface -----------
    [ServiceContract]
    public interface IGenericService<T>
    {
        [OperationContract]
        T Echo(T subject);
    }

    public class GenericService<T>: IGenericService<T>
    {
        public T Echo(T subject)
        {
            return subject;
        }
    }

    //-- Non-generic variant where T is set to be a string --

    [ServiceContract]
    public interface INonGenericService : IGenericService<string>
    {}

    public class NonGenericService: GenericService<string>, INonGenericService
    {}
}

      

In app.config, I can configure the service like this:

  <system.serviceModel>
    <services>
      <service name="ServiceExample.NonGenericService">

        <endpoint 
          address="http://localhost:1111/" 
          binding="basicHttpBinding" 
          contract="ServiceExample.INonGenericService" />

      </service>
    </services>
 </system.serviceModel>

      

This works great.

However, I find it very annoying to have to define these empty non-common versions of the service class (and service contract) for the sole purpose of getting some valid non-common names to be put in the .config file.

Why don't I specify directly in the .config file that I want a line-version of the generic class and interface? I guess it can be done like this:

  <system.serviceModel>
    <services>
      <service name="ServiceExample.GenericService`1[[System.String]], mscorlib">

        <endpoint
          address="http://localhost:1111/"
          binding="basicHttpBinding"
          contract="ServiceExample.IGenericService`1[[System.String]], mscorlib" />

      </service>
    </services>
  </system.serviceModel>

      

I tried very hard, but unsuccessfully so far. Is this not possible at all?

+3


source to share





All Articles