2012-02-13 13 views
3

私は約15-20のサービスを持っています。各サービスには独自の契約と実装ファイルがあります。私は開発中にデバッグするのがより簡単になるように、コンソールアプリケーションでこれらのサービスをすべてホストしたいと考えています。コンソールのホストWCFサービス

プロジェクト構造

  • サービス - ソリューション
    • ServiceContracts - プロジェクト
    • 実装 - プロジェクト
    • のServiceHost - Windowsサービスプロジェクト - 既にインプレースや細かい作業...
    • ServiceConsoleHost - プロジェクト - 現在作業中です。私はここにServiceConsoleHostプロジェクト設定ファイルからのサンプルテキストでapp.configファイルを持っている

...事前に

<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> 

おかげで...あなたはおそらく探している

+3

質問は何ですか? – Rajesh

+0

これらのサービスをコンソールapp-inループでホストするコードが必要です。 – venky

+1

"in loop"とはどういう意味ですか?また、app.configにはnet.tcpバインディングとmexhttpbindingがあり、サービス名は完全修飾されていません。 – Rajesh

答えて

2

自己ホストサービス。 ServiceHostを使用して自己ホスティングについてはMSDN Referenceを参照してください。

enumerating WCF configuration bindingsもご覧ください。ここにはenumerating WCF service and endpoint bindingsを記載したSOの投稿があります。

+0

私はすでにそれを見て - すべての例は、単一のサービスをホストする方法を示しています - 私の場合は15サービスを持っていて、サービス。 – venky

+1

@venky - あなたはあなたが持っているサービスごとに別々の 'ServiceHost'が必要です。 – SliverNinja

+0

すべてのサービスを保持するためにserviceHostをコレクションとして使用できますか? – venky

1

15人のサービスをホストするには15のServiceHostsが必要です。しかし、彼らはブロックされていません。サービスが実行されている間、MSDNコードがキーを押すのを待っていることに気づいた場合。これは、すべてのサービスコードが別のスレッドで実行されていることを意味します。したがって、15のサービスの作成とホスティングは問題ではありません。 ServiceHost.Open()を実行すると、既に処理されているので、 "ループ"は必要ありません。

関連する問題