2017-07-17 7 views
0

複数のServiceHostインスタンスを設定すると、1つのポートに対して1つのホストしか使用できません。ServiceHostとIIS間のリンクがありません

Uri baseAddressHttps = new Uri("https://localhost/myservice.svc"); 
ServiceHost host = new ServiceHost(typeof(MyService), baseAddressHttps); 
... 
host.Open(); //OK 

ServiceHost host2 = new ServiceHost(typeof(MyService), baseAddressHttps); 
... 
host2.Open(); //Fail 

host2.Open()への2回目の呼び出しは、期待どおりに失敗します。

最近、私はServiceHostの偶然の行動を見つけました。 マシン(Windows Server 2012 R2)は、https://localhostをカバーするIISを実行していました。ホストされているサイトはなく、IISは基本的に何もしませんでした。 アドレスhttps://localhost/myservice.svcでWCF ServiceHostを使用するプログラム(通常のWindowsサービス)をインストールしても問題なく動作しました。

私はIISを構成していないし、実行中のIISがあることをServiceHostに通知しなかった。ポートの競合が起こっていない可能性はありますか? ServiceHostはどのダークマジックを使用していますか?何が起こっているのか理解したいだけです。

答えて

0

httpでリッスンしているのではなく、http.sysドライバ(HTTP サービス)がWindows OSでこれを実行しています。また、この魔法は http.sysレベルで行われます。これを実行して、どのアプリケーションが であるかを知ることができます.IIS(w3wp.exeプロセス)またはWindowsサービス(HTTPリスナーを使用しています)でリッスンしますHTTP.sysによって提供されるキュー

は、特定のプロセスがの一部に聞くことができ登録のURLを見て、あなたは上記の出力で見たようあなたはnetshコマンド

C:\windows\system32>netsh http show servicestate 

Snapshot of HTTP service state (Server Session View): 
----------------------------------------------------- 

Server session ID: FF00000020000001 
    Version: 2.0 
    State: Active 
    Properties: 
     Max bandwidth: 4294967295 
     Timeouts: 
      Entity body timeout (secs): 120 
      Drain entity body timeout (secs): 120 
      Request queue timeout (secs): 65535 
      Idle connection timeout (secs): 120 
      Header wait timeout (secs): 120 
      Minimum send rate (bytes/sec): 240 
    URL groups: 
    URL group ID: FE00000040000001 
     State: Active 
     Request queue name: DefaultAppPool 
     Properties: 
      Max bandwidth: inherited 
      Max connections: 4294967295 
      Timeouts: 
       Entity body timeout (secs): 120 
       Drain entity body timeout (secs): 120 
       Request queue timeout (secs): 65535 
       Idle connection timeout (secs): 120 
       Header wait timeout (secs): 0 
       Minimum send rate (bytes/sec): 0 
      Logging information: 
       Log directory: C:\inetpub\logs\LogFiles\W3SVC1 
       Log format: 0 
      Authentication Configuration: 
       Authentication schemes enabled: 
    URL group ID: FD00000040000001 
     State: Active 
     Request queue name: testweb 
     Properties: 
      Max bandwidth: inherited 
      Max connections: inherited 
      Timeouts: 
       Timeout values inherited 
      Authentication Configuration: 
       Authentication schemes enabled: 
      Number of registered URLs: 1 
      Registered URLs: 
       HTTP://*:80/BUGGYBITS/ 
    URL group ID: FF00000240000001 
     State: Active 
     Request queue name: testweb 
     Properties: 
      Max bandwidth: inherited 
      Max connections: 4294967295 
      Timeouts: 
       Entity body timeout (secs): 120 
       Drain entity body timeout (secs): 120 
       Request queue timeout (secs): 65535 
       Idle connection timeout (secs): 120 
       Header wait timeout (secs): 0 
       Minimum send rate (bytes/sec): 0 
      Logging information: 
       Log directory: C:\inetpub\logs\LogFiles\W3SVC2 
       Log format: 0 
      Authentication Configuration: 
       Authentication schemes enabled: 
      Number of registered URLs: 1 
      Registered URLs: 
       HTTP://*:80/ 

Server session ID: FF00000120000001 
    Version: 2.0 
    State: Active 
    Properties: 
     Max bandwidth: 4294967295 
     Timeouts: 
      Entity body timeout (secs): 120 
      Drain entity body timeout (secs): 120 
      Request queue timeout (secs): 120 
      Idle connection timeout (secs): 120 
      Header wait timeout (secs): 120 
      Minimum send rate (bytes/sec): 150 
    URL groups: 
    URL group ID: FE00000140000001 
     State: Active 
     Request queue name: Request queue is unnamed. 
     Properties: 
      Max bandwidth: inherited 
      Max connections: inherited 
      Timeouts: 
       Timeout values inherited 
      Number of registered URLs: 1 
      Registered URLs: 
       HTTP://*:5357/B5B45532-3676-4316-BBB8-9DBB35BACAB4/ 

Request queues: 
    Request queue name: DefaultAppPool 
     Version: 2.0 
     State: Active 
     Request queue 503 verbosity level: Limited 
     Max requests: 1000 
     Number of active processes attached: 0 
     Controller process ID: 3016 
     Process IDs: 

    Request queue name: testweb 
     Version: 2.0 
     State: Active 
     Request queue 503 verbosity level: Limited 
     Max requests: 1000 
     Number of active processes attached: 0 
     Controller process ID: 3016 
     Process IDs: 

を実行することができ、この動作を確認するにはURL。この場合、HTTP:// :80/BUGGYBITS /が特定のプロセスに進み、HTTP://:80 /が別のプロセスに移動します。

これはクリアです.netshコマンドの詳細については、here