IIS主机中的WCF库无法从客户端连接

时间:2013-02-12 21:06:14

标签: c# wcf iis

您好我有一个WCF服务库项目,我已经创建了一个WPF应用程序来托管它进行测试,并且工作正常,但我还创建了一个Web应用程序来在IIS中托管它以进行生产,当我尝试连接到我永远不能做的II。

我正在使用net.tcp绑定,我已经进入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>

2 个答案:

答案 0 :(得分:1)

好的,我终于搞清楚了。

首先我必须补充:

<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无论如何都要提供地址。

答案 1 :(得分:0)

会发生什么?你有例外吗?你能在IIS中浏览吗?

您的服务有:

endpoint address="net.tcp://localhost:808/EcuWebService/mex"

和客户:

endpoint address="net.tcp://localhost/EcuWebService/service"

我认为你需要提供更多细节才能得到一个好的答案。