0

IIS でホストされている場合に参照を追加すると正常に実行されている WCF サービスがありますが、win アプリケーションでホストしようとするとクライアント アプリが見つかりません。これは、NetTcpBinding を使用した場合にのみ発生します。「メッセージを受け入れることができる net.tcp://localhost:5566/ でリッスンしているエンドポイントがありませんでした」というエラーが表示されます。私がbasicHttpBindingを使用しているとき、すべてが機能しています。

サービスの構成ファイルは次のとおりです

<system.serviceModel>
<services>
  <service name="TestWcfService.Service1" behaviorConfiguration="TestWcfService.Service1Behavior">
    <!-- Service Endpoints -->
    <endpoint address="" binding="netTcpBinding" contract="TestWcfService.IService1">
      <!-- 
          Upon deployment, the following identity element should be removed or replaced to reflect the 
          identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
          automatically.
      -->
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="TestWcfService.Service1Behavior">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="false"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

そして、これがホストアプリのコードです

ServiceHost host = new ServiceHost(typeof(Service1), new Uri("net.tcp://localhost:5566"));
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = false;
host.Description.Behaviors.Add(behavior);
host.AddServiceEndpoint(typeof(IService1), new NetTcpBinding(), "Service1");
host.AddServiceEndpoint(typeof(IMetadataExchange), new NetTcpBinding(), "MEX");
host.Open();
4

1 に答える 1

0

次のように TCP エンドポイントを追加すると:

ServiceHost host = new ServiceHost(typeof(Service1), 
                                   new Uri("net.tcp://localhost:5566"));

host.AddServiceEndpoint(typeof(IService1), new NetTcpBinding(), "Service1");

サービスアドレスはnet.tcp://localhost:5566/Service1(コンストラクターで定義されたベースアドレスServiceHostと、呼び出しで定義された相対アドレスAddServiceEndpoint)になります-そこにメッセージを送信しようとしましたか??

于 2010-12-23T16:38:27.790 に答える