3

I have around 15-20 services - each service has its own contract and implementation file. I want to host all these service in a console app so that it will be easier to debug during development.

Project structure

  • Services - Solution
    • ServiceContracts - Project
    • Implementation - Project
    • ServiceHost - Windows Service project -- Already inplace and working fine..
    • ServiceConsoleHost - Project - Currently working on it.

I have an app.config file in the ServiceConsoleHost project here the sample text from config file...

<service name="TestpricingService" behaviorConfiguration="HostBehavior">
<host>
   <baseAddresses>
        <add baseAddress="http://localhost:8000/testService/pricingService"/>
   </baseAddresses>
</host>
    <!-- use base address provided by host -->
    <endpoint address="net.tcp://localhost:820/testService/pricingService"
                      binding="netTcpBinding"
                      bindingConfiguration="HostBinding"
                      contract="Test.Services.Contracts.IpricingService" />
    <!-- the mex endpoint is exposed at http://localhost:8000/testService/purchasing/mex -->
    <endpoint address="mex"
    binding="mexHttpBinding"
    contract="IMetadataExchange" />
</service>
<behaviors>
  <serviceBehaviors>
    <behavior name="HostBehavior">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="True" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
    <behavior name="PooledHostBehavior">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="True" />
      <ObjectPoolingServiceBehavior minPoolSize="0" maxPoolSize="5" idleTimeOut="30000"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

Thanks in advance...

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
venky
  • 55
  • 1
  • 7
  • Need code to host these services in console app - in loop. – venky Feb 13 '12 at 16:40
  • 1
    What do you mean by "in loop"? Also in your app.config you have a net.tcp binding and a mexhttpbinding and your service name is not fully qualified. – Rajesh Feb 13 '12 at 16:41
  • What i'm trying to do here is... trying to host all those 15 services in console app.. instead of creating host object for each service - can we use servicehost collection for somthing like that? – venky Feb 13 '12 at 16:47
  • want to host service using nettcp binding.. – venky Feb 13 '12 at 16:48
  • 1
    When you say single host are you referring to a single port for your net tcp binding. If that is the case then look at this article: http://msdn.microsoft.com/en-us/library/aa395195.aspx – Rajesh Feb 13 '12 at 16:57
  • 1
    One `ServiceHost` can host exactly **one service** - so if you need to host 15 services, you need 15 instances of `ServiceHost` – marc_s Feb 13 '12 at 17:12

2 Answers2

2

You are probably looking for self-hosted services. See MSDN Reference on self-hosting using ServiceHost.

Also take a look at enumerating WCF configuration bindings. Here is an SO post which describes enumerating WCF service and endpoint bindings.

Community
  • 1
  • 1
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
1

as everyone mentioned you need 15 ServiceHosts to host 15 services. However they are not blocking. If you notice the MSDN code just sits waiting for a keypress whilst the service is running. This means all the service code is running on separate threads. So creating and hosting 15 services is not an issue. You dont need a "loop" as that is already handled once you do ServiceHost.Open().

cdturner
  • 392
  • 3
  • 11