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

问题描述 投票:0回答:1

我的客户端有这个错误。 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;
c wpf wcf
1个回答
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 如果有什么我可以帮忙,请随时告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.