System.ServiceModel.CommunicationException:'接收HTTP时发生错误

时间:2019-04-29 18:10:03

标签: c wpf wcf

我的客户遇到此错误。 System.ServiceModel.CommunicationException:'收到对http://localhost:8099/IService的HTTP响应时发生错误。这可能是由于服务端点绑定未使用HTTP协议。这也可能是由于服务器终止了HTTP请求上下文(可能是由于服务关闭了)。请参阅服务器日志以获取更多详细信息。 客户端配置

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <!-- 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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IProgrammService" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8099/IService" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProgrammService" contract="ServiceReferenceMrChicken.IProgrammService" name="BasicHttpBinding_IProgrammService" />
    </client>
  </system.serviceModel>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v14.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="EmployeeConnection" connectionString="Data Source=den1.mssql7.gear.host;Initial Catalog=mrchikendb;User ID=mrchikendb;Password=Qwer-12" providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

服务器配置

<?xml version="1.0" encoding="utf-8"?>
<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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
  <system.serviceModel>
    <bindings />
    <client />
    <services>
      <service name="IService.ProgrammService" behaviorConfiguration="mexBehavior">
        <endpoint address="IService" binding="basicHttpBinding" contract="IService.IProgrammService"></endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8099/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
          <serviceThrottling maxConcurrentCalls="120" maxConcurrentSessions="120"
                             maxConcurrentInstances="120" />
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v14.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="EmployeeConnection" connectionString="Data Source=den1.mssql7.gear.host;Initial Catalog=mrchikendb;User ID=mrchikendb;Password=Qwer-12" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="C:\TracesServ_ce.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
</configuration>

我拒绝的代码

ServiceReferenceMrChicken.ProgrammServiceClient client = new ServiceReferenceMrChicken.ProgrammServiceClient();
            var users = client.GetUsers();
            dataGrid.ItemsSource = users;

我拒绝的代码

ServiceReferenceMrChicken.ProgrammServiceClient client = new ServiceReferenceMrChicken.ProgrammServiceClient();
            var users = client.GetUsers();
            dataGrid.ItemsSource = users;

1 个答案:

答案 0 :(得分:0)

在托管服务的过程中,对我来说似乎有些不对劲。您可以通过访问服务的WSDL来验证它是否被正确托管。

http://x.x.x.x:8009/service1.svc?wsdl

通常,服务端点地址由IIS站点绑定而不是服务配置文件的基地址提供,因为WCF服务也由IIS托管为网站。 因此,以下代码段是不必要的。

   <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8099/" />
      </baseAddresses>
    </host>

同时,我们应该在IIS网站绑定模块中提供一个http基地址。 enter image description here
然后服务地址将为http://x.x.x.x:9001/service1.svc,我们可以使用“添加服务引用向导”键入服务基址以在客户端使用它。
enter image description here
随时让我知道是否有什么可以帮助您的。