我有一个运行正常的WCF服务,如果我在IIS中托管时添加对它的引用,但是当我尝试在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();
答案 0 :(得分: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
调用中定义的相对地址) - 您是否尝试过在那里发送消息? ?