您好,我有一个 WCF 服务库项目,并且我创建了一个 WPF 应用程序来托管它以进行测试并且效果很好,但是我还创建了一个 Web 应用程序来在 IIS 中托管它以进行生产,并且当我尝试连接到 IIs 时我永远做不到。
我正在使用 net.tcp 绑定,我已进入 IIS 并将 net.tcp 绑定添加到 Web 应用程序和网站。
基本上这是一个双工服务,其方法标记为单向。当我在客户端调用该方法时,回调永远不会被调用,我最终只是坐在那里等待几分钟,然后关闭应用程序。当我自己托管服务时,我几乎立即在回调中得到响应。
我也尝试过使用 localhost:808 和 localhost。如果我使用 svcutil 生成配置,它会使端口脱离地址。我没有收到任何我知道的错误,但老实说,我真的不知道如何判断我是否收到了它从 IIS 抛出的任何错误。
此外,如果我去http://localhost:9595/EcuWebService/Service.svc
我会得到告诉我使用 svcutil 生成我的客户端代理的页面。
正如乔克在下面建议的那样,我附加了一个调试器并收到了这个错误:服务'/EcuWebService/service'不存在。
这里也是我的 svc 文件的内容:
<%@ ServiceHost Language="C#" Debug="true" Service="EcuWeb.ServiceLib.Contracts.EcuWebServiceMain" %>
下面是我的 Web.config:
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" minFreeMemoryPercentageToActivateService="1" multipleSiteBindingsEnabled="true"/>
<services>
<service name="EcuWeb.ServiceLib.Contracts.EcuWebServiceMain">
<endpoint address="net.tcp://localhost:808/EcuWebService/service" binding="netTcpBinding" bindingConfiguration="" name="netTcp_EcuWebServiceEndpoint" contract="EcuWeb.ServiceLib.Contracts.IEcuWebServiceMain">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="net.tcp://localhost:808/EcuWebService/mex" binding="mexTcpBinding" bindingConfiguration="" name="mexTcp_EcuWebServiceEndpoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/EcuWebService" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
这是客户端应用程序的配置。注释掉的端点是我不在 IIS 中托管时使用的端点,它可以工作。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTcp_EcuWebServiceEndpoint" />
</netTcpBinding>
</bindings>
<client>
<!--<endpoint address="net.tcp://localhost:5555/EcuWebService/service"
binding="netTcpBinding" bindingConfiguration="netTcp_EcuWebServiceEndpoint"
contract="EcuWebService.IEcuWebServiceMain" name="netTcp_EcuWebServiceEndpoint">
<identity>
<dns value="localhost" />
</identity>
</endpoint>-->
<endpoint address="net.tcp://localhost/EcuWebService/service"
binding="netTcpBinding" bindingConfiguration="netTcp_EcuWebServiceEndpoint"
contract="EcuWebService.IEcuWebServiceMain" name="netTcp_EcuWebServiceEndpoint">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<services>
<service name="Ecu.Service.Contracts.EcuServiceMain">
<endpoint address="service" binding="netNamedPipeBinding" bindingConfiguration=""
name="netNamedPipe_EcuClientEndpoint" contract="Ecu.Service.Contracts.IEcuServiceMain">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexNamedPipeBinding" bindingConfiguration=""
name="mexNamedPipe_EcuClientEndpoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/EcuServiceClient" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>