System.ServiceModel.CommunicationException: '接收 HTTP 时发生错误
System.ServiceModel.CommunicationException: 'An error occurred while receiving the HTTP
我的客户端有这个错误。
System.ServiceModel.CommunicationException: 'An error occurred while receiving the HTTP response to http://localhost:8099/IService. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.'
客户端配置
<?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;
在托管服务的过程中,您的配置在我看来可能有问题。您可以通过访问服务的 WSDL 来验证它是否被正确托管。
http://x.x.x.x:8009/service1.svc?wsdl
通常,服务端点地址由 IIS 站点绑定提供,而不是服务配置文件的基地址,因为 WCF 服务也作为网站由 IIS 托管。
所以下面的代码片段是不必要的。
<host>
<baseAddresses>
<add baseAddress="http://localhost:8099/" />
</baseAddresses>
</host>
同时,我们应该在IIS站点绑定模块中提供一个http基地址。
然后服务地址将是 http://x.x.x.x:9001/service1.svc,我们可以使用添加服务引用向导键入服务基址以在客户端使用它。
如果有什么我可以帮忙的,请随时告诉我。
我的客户端有这个错误。 System.ServiceModel.CommunicationException: 'An error occurred while receiving the HTTP response to http://localhost:8099/IService. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.' 客户端配置
<?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;
在托管服务的过程中,您的配置在我看来可能有问题。您可以通过访问服务的 WSDL 来验证它是否被正确托管。
http://x.x.x.x:8009/service1.svc?wsdl
通常,服务端点地址由 IIS 站点绑定提供,而不是服务配置文件的基地址,因为 WCF 服务也作为网站由 IIS 托管。 所以下面的代码片段是不必要的。
<host>
<baseAddresses>
<add baseAddress="http://localhost:8099/" />
</baseAddresses>
</host>
同时,我们应该在IIS站点绑定模块中提供一个http基地址。
然后服务地址将是 http://x.x.x.x:9001/service1.svc,我们可以使用添加服务引用向导键入服务基址以在客户端使用它。
如果有什么我可以帮忙的,请随时告诉我。