2

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.

Jens Kloster
  • 11,099
  • 5
  • 40
  • 54

3 Answers3

1

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.

Community
  • 1
  • 1
Wali
  • 440
  • 1
  • 4
  • 21
  • The link have it vice versa. I only have one contract, but multiple implementations of that contract. also the link didn't provide any information on how to host the darn thing :) But thanks for feedback – Jens Kloster Feb 08 '13 at 22:16
  • Well in the above post, there is only 1 Contract and 2 implementations, am not sure why it did not helped you. I have edited the answer and added one more link. Hope it helps... – Wali Feb 09 '13 at 05:06
  • I'll give you one for trying, but the link is not what i was looking for. sry – Jens Kloster Feb 11 '13 at 07:27
0

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

Jens Kloster
  • 11,099
  • 5
  • 40
  • 54
0

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

Schwarzie2478
  • 2,186
  • 26
  • 30
  • hi - thnks for the feedback. No unfortnally i can't. because the endpoint don't let me decide what implementation i uses. that is specified in the service tag: `` – Jens Kloster Feb 08 '13 at 12:41