Jens Kloster
Jens Kloster

Reputation: 11277

WCF multiple services same contract in same Config

Im trying to host to different service implementations of the same contract:

Model

The reason is that need a dummy implementation for out-of-the-house testing.

Im trying to host both in the same WindowsService:

    private ServiceHost _host;
    private ServiceHost _dummy;
    protected override void OnStart(string[] args)
    {
        _host = new ServiceHost(typeof(Service));
        _host.Open();

 //trying to avoid the app.config beeing used - because its already been hoste by _host
        _dummy = new ServiceHost(typeof(TestDummyService));
        _dummy.Description.Endpoints.Clear();
        _dummy.AddServiceEndpoint(typeof(IService), 
                                   new WebHttpBinding(),
                                  @"<link>/Dummy.svc/");
        _dummy.ChannelDispatchers.Clear();
        _dummy.Open();
     }

This is the config file:

  <system.serviceModel>
    <services>
      <service name="namespace.Service">
        <host>
          <baseAddresses>
            <add baseAddress="<link>/Service.svc"/>
          </baseAddresses>
        </host>
        <endpoint address="" 
                  binding="webHttpBinding" 
                  contract="namespace.IService" 
                  behaviorConfiguration="web" />

        <endpoint address="/mex" 
                  binding="mexHttpBinding" 
                  contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors >
        <behavior>
          <serviceMetadata httpGetEnabled="true"
                           httpGetUrl="<link>/Service.svc/About" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name ="web">
          <webHttp />         
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

The ChannelDispatcher at /Service.svc/About with Contracts ‘IHttpGetHelpPageAndMetadataContract’ is unable to open.

any help is appreciated.

Update 1 My goal is to have 2 different implementations of the same contract (IService) hosted in one WindowsService.

I would also like to configure both of them in the config file.

Upvotes: 2

Views: 3378

Answers (3)

Wali
Wali

Reputation: 440

Well i would like to know what's the business scenario. All I guess is, the client should not know the implementation, its just the URL of the service would indicate (or route) to the implementation.

Kindly clarify.


Refer to this existing post and let me know if it makes sense.


The above post is hinting the implementation, refer to this post for deployment details.

Upvotes: 1

Schwarzie2478
Schwarzie2478

Reputation: 2276

Can't you add another endpoint and fill in the adress with a distinct name:

<endpoint address="/SecondService" 
              binding="webHttpBinding2" 
              contract="namespace.IService" 
               />

Url becomes /Service.svc/SecondService

Upvotes: 0

Jens Kloster
Jens Kloster

Reputation: 11277

so i found out, that even thow the testdummy service was added programatic, it still got the service metadatabehavior.

My solution was to not make the dehavior default - given it at name:

app.config:

<service name="namespace.Service" behaviorConfiguration="someName">

//.. later:

    <behavior name="someName">
      <serviceMetadata httpGetEnabled="true"
                       httpGetUrl="<link>/Service.svc/About" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>

The rest of the code, statyed the same

Upvotes: 0

Related Questions