[英]WCF Library in IIS Hosting not connecting from client
您好,我有一个WCF服务库项目,并且我已经创建了一个WPF应用程序来承载它进行测试,并且效果很好,但是我还创建了一个Web应用程序来承载它在IIS中进行生产,以及尝试连接到IIs时我永远做不到
我正在使用net.tcp bininding,并且已经进入IIS,并将net.tcp biniding添加到Web应用程序和网站中。
基本上,这是一种双工服务,其方法标记为一种方法。 当我在客户端中调用该方法时,永远不会调用该回调,而最终我只是坐在那里等待了几分钟,然后关闭了应用程序。 当我自托管服务时,几乎立即在回调上得到响应。
我也尝试使用localhost:808和localhost。 如果我使用svcutil生成配置,它将使端口脱离地址。 我没有发现任何错误,但是老实说我真的不知道如何判断是否从IIS抛出了任何错误。
另外,如果我转到http://localhost:9595/EcuWebService/Service.svc
看到告诉我使用svcutil生成客户端代理的页面。
正如Jocke在下面建议的那样,我连接了调试器并收到此错误:服务'/ 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>
好吧,我终于明白了。
首先,我必须添加:
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:5555/EcuWebService" />
<add baseAddress="http://localhost/EcuWebService" />
</baseAddresses>
</host>
然后对于我刚刚使用的端点:
<service name="EcuWeb.ServiceLib.Contracts.EcuWebServiceMain">
<endpoint address="service" binding="netTcpBinding" bindingConfiguration=""
name="netTcp_EcuWebServiceEndpoint" contract="EcuWeb.ServiceLib.Contracts.IEcuWebServiceMain">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
然后在客户端中,我必须使用:
<endpoint address="net.tcp://localhost/EcuWebService/Service.svc/service"
binding="netTcpBinding" bindingConfiguration="netTcp_EcuWebServiceEndpoint"
contract="EcuWebService.IEcuWebServiceMain" name="netTcp_EcuWebServiceEndpoint">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
当我添加端口时,它不起作用,但是一旦删除它,它就没有问题。 我也怀疑基址是必需的,因为IIS无论如何都给出了该地址。
怎么了? 你有例外吗? 您可以在IIS中浏览它吗?
您的服务有:
endpoint address="net.tcp://localhost:808/EcuWebService/mex"
和客户:
endpoint address="net.tcp://localhost/EcuWebService/service"
我认为您需要提供更多详细信息才能获得良好的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.