WCF multiple serving the same contract in the same configuration

I am trying to do different service implementations of the same contract:

Model

The reason is that a dummy implementation is needed for testing outside the home.

I'm trying to host both in one 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>

      

Channel-Dispatcher at /Service.svc/About with Contracts' IHttpGetHelpPageAndMetadataContract cannot open.

any help is appreciated.

Update 1 My goal is to have two different implementations of the same contract ( IService

) hosted in the same WindowsService.

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

+2


source to share


3 answers


so I found out that even though the testdummy service was added programmatically, it still got the service behavior metadata.

My solution was to not set the default by default - given its 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, the old one is the same

0


source


Ok, I would like to know what a business scenario is. All I'm guessing is the client doesn't need to know the implementation, its only the service url points (or route) to the implementation.

Please clarify.




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




The article above hints at the implementation, refer to the post for deployment details.

+1


source


It is not possible to add another endpoint and fill the address with a different name:

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

      

Url becomes / Service.svc / SecondService

0


source







All Articles