C# 连接到WCF服务时出现问题

C# 连接到WCF服务时出现问题,c#,asp.net,.net,web-services,wcf,C#,Asp.net,.net,Web Services,Wcf,我正在学习WCF,在托管服务后访问该服务时遇到了一些问题。我创建了一个WCF服务,该服务在Web.config中有以下条目- 服务Web.config <system.serviceModel> <behaviors> <serviceBehaviors> <behavior> <!-- To avoid disclosing metadata information, set the values below to

我正在学习WCF,在托管服务后访问该服务时遇到了一些问题。我创建了一个WCF服务,该服务在Web.config中有以下条目-

服务Web.config

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <!-- 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>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<bindings>
  <basicHttpBinding>
    <binding maxReceivedMessageSize="2147483647"
             maxBufferSize="2147483647"
             maxBufferPoolSize="2147483647">
      <readerQuotas maxDepth="32"
                    maxArrayLength="2147483647"
                    maxStringContentLength="2147483647"/>
    </binding>
  </basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
<system.serviceModel>    
<services>
  <service name="ServiceName"
           behaviorConfiguration="ServiceNameBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:59918/ServiceName.svc"/>
      </baseAddresses>
    </host>
    <endpoint address=""
              binding="wsHttpBinding"
              contract="ServiceName.IServiceName" />
    <endpoint address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceNameBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="False"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

并创建了一个负责托管此服务的控制台应用程序。这是主机的App.config-

主机App.config

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <!-- 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>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<bindings>
  <basicHttpBinding>
    <binding maxReceivedMessageSize="2147483647"
             maxBufferSize="2147483647"
             maxBufferPoolSize="2147483647">
      <readerQuotas maxDepth="32"
                    maxArrayLength="2147483647"
                    maxStringContentLength="2147483647"/>
    </binding>
  </basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
<system.serviceModel>    
<services>
  <service name="ServiceName"
           behaviorConfiguration="ServiceNameBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:59918/ServiceName.svc"/>
      </baseAddresses>
    </host>
    <endpoint address=""
              binding="wsHttpBinding"
              contract="ServiceName.IServiceName" />
    <endpoint address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceNameBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="False"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

我运行了主机并安装了服务。我现在可以从services.msc启动/停止服务,也可以将引用正确添加到客户端。问题是,当我调用任何服务方法时,客户机无法连接到它,只是超时。为什么会这样?这里的Web.config和App.config是否正确


注意:我还处理大量传入和传出服务的数据。这就是我设置MaxReceivedMessageSize参数的原因。

您没有更改超时。很可能传输消息所需的时间超过了允许的时间。使用较少的数据进行测试,以验证服务和客户端是否实际工作。然后找出你需要什么超时。我已经测试了没有主机的服务,包括在同一个项目中。没有任何问题。返回数据的时间不到2秒。如果您在控制台应用程序中托管数据,则web.config是多余的。另外,如果您打算使用wsHttpBinding,那么您的服务基址URL方案应该是https而不是http。您还需要允许您的服务侦听
http://localhost:59918/
使用
netsh
。您的ServiceHost抛出异常,在web上搜索该异常,您将了解如何执行该操作。它还可以帮助您在问题中包括所有相关的详细信息,例如您以前的评论和客户端的实际异常。@PankajKapare我是否应该在App.config中设置MaxReceivedMessageSize设置?