WCF接收HTTP响应时发生错误

时间:2016-05-10 14:46:35

标签: c# .net wcf

我收到此错误:An unhandled exception of type 'System.ServiceModel.CommunicationException'

完整的错误描述:

  

未处理的类型异常   mscorlib.dll中出现'System.ServiceModel.CommunicationException'

     

其他信息:接收HTTP时发生错误   回应   http://localhost:8733/Design_Time_Addresses/SnUpdateService/Service1/。   这可能是由于服务端点绑定不使用HTTP   协议。这也可能是由于HTTP请求上下文所致   由服务器中止(可能是由于服务关闭)。看到   服务器日志以获取更多详细信息。

在clien中我试图获得流数据的响应

  SnUpdateService.Service1Client SnService = new     SnUpdateService.Service1Client();
       SnUpdateService.UpdateFiles com = new SnUpdateService.UpdateFiles();
       com.Path = "C:\\temp";
       com.SearchType = 1;
       com.Version = "20150101";
       SnUpdateService.UpdateFiles comReturn = new SnUpdateService.UpdateFiles();
       comReturn = SnService.GetUpdateFiles(com);//here error

如果没有流数据,则一切正常。

我做错了什么?

这是我的客户端配置

<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
      </startup>
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="BasicHttpBinding_IService1" maxBufferPoolSize="200000000"
              maxReceivedMessageSize="200000000" />
          </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://localhost:8733/Design_Time_Addresses/SnUpdateService/Service1/"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
            contract="SnUpdateService.IService1" name="BasicHttpBinding_IService1" />
        </client>
      </system.serviceModel>
    </configuration>

这是我的服务器webConfig

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <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>
    <services>
      <service name="SnUpdateService.Service1">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8733/Design_Time_Addresses/SnUpdateService/Service1/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" contract="SnUpdateService.IService1">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> 
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <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>
  </system.serviceModel>

</configuration>

2 个答案:

答案 0 :(得分:0)

我认为您缺少客户端配置文件中绑定配置 BasicHttpBinding_IService1 的定义。

此外,您可以将includeExceptionDetailInFaults =“False”设置为“true”以获得更详细的堆栈跟踪。这有助于您调试。

答案 1 :(得分:-2)

我在一段时间内遇到了同样的问题并通过在我的服务托管的应用程序池中启用32位应用程序来解决它。