2010-05-23 65 views
1

我有流式傳輸問題。當我送小文件中像1KB TXT一切正常,但是當我發送更大的文件中像100 KB JPG或PSD 2GB我得到:遠程服務器返回意外響應:(400)流式傳輸時請求錯誤

The remote server returned an unexpected response: (400) Bad Request. 

我使用的是Windows 7中,VS 2010和.NET 3.5和WCF服務庫

我失去了對這個我所有的週末,我仍然看到此錯誤:/請幫我

客戶:

var client = new WpfApplication1.ServiceReference1.Service1Client("WSHttpBinding_IService1"); 

     client.GetString("test"); 
     string filename = @"d:\test.jpg"; 
     FileStream fs = new FileStream(filename, FileMode.Open); 
     try 
     { 
      client.ProcessStreamFromClient(fs); 
     } 
     catch (Exception exception) 
     { 
      Console.WriteLine(exception); 
     } 

的app.config:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="StreamedHttp" closeTimeout="10:01:00" openTimeout="10:01:00" 
      receiveTimeout="10:10:00" sendTimeout="10:01:00" allowCookies="false" 
      bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferSize="65536000" maxBufferPoolSize="524288000" maxReceivedMessageSize="65536000" 
      messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed" 
      useDefaultWebProxy="true"> 

      <readerQuotas maxDepth="0" maxStringContentLength="0" maxArrayLength="0" 
      maxBytesPerRead="0" maxNameTableCharCount="0" /> 
      <security mode="None"> 
      <transport clientCredentialType="None" proxyCredentialType="None" 
      realm="" /> 
      <message clientCredentialType="UserName" algorithmSuite="Default" /> 
      </security> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary2/Service1/" 
     binding="basicHttpBinding" bindingConfiguration="StreamedHttp" 
     contract="ServiceReference1.IService1" name="WSHttpBinding_IService1" /> 
    </client> 
    </system.serviceModel> 
</configuration> 

和WCF ServiceLibrary:

public void ProcessStreamFromClient(Stream str) 
     { 

//error occuring even this method is empty 
      using (var outStream = new FileStream(@"e:\test.jpg", FileMode.Create)) 
      { 
       var buffer = new byte[4096]; 
       int count; 
       while ((count = str.Read(buffer, 0, buffer.Length)) > 0) 
       { 
        outStream.Write(buffer, 0, count); 
       } 
      } 
     } 

的App.config

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

    <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> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="Binding1" 
       hostNameComparisonMode="StrongWildcard" 


       maxBufferSize="65536000" 

       transferMode="Streamed" 

       bypassProxyOnLocal="false" 

       closeTimeout="10:01:00" 

openTimeout="10:01:00" receiveTimeout="10:10:00" sendTimeout="10:01:00" 

maxBufferPoolSize="524288000" maxReceivedMessageSize="65536000" messageEncoding="Text" 
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> 
      <security mode="None" /> 
     </binding> 
     </basicHttpBinding> 

    </bindings> 
    <client /> 
    <services> 
     <service name="WcfServiceLibrary2.Service1"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary2/Service1/" /> 
      </baseAddresses> 
     </host> 
     <!-- Service Endpoints --> 
     <!-- Unless fully qualified, address is relative to base address supplied above --> 
     <endpoint address="" binding="basicHttpBinding" contract="WcfServiceLibrary2.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 value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="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 --> 
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
      <!-- 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> 

回答

1

嘗試設置:

<serviceDebug includeExceptionDetailInFaults="true" /> 

它不會解決問題,但你可能會得到一個錯誤消息指出問題所在。

+0

這裏是錯誤:public void ProcessStreamFromClient(System.IO.Stream stream){ base.Channel.ProcessStreamFromClient(stream);如果我的webmethod爲空仍然會出錯。你有什麼想法 – user278618 2010-05-23 18:55:27

+0

嘗試發送一個小文件並檢查它是否仍然有效,然後嘗試逐漸增加文件的大小以找出限制的位置。 – 2010-05-23 19:33:22

+7

這被標記爲答案,但沒有關於實際解決方案的解釋。 – jpierson 2012-01-20 21:55:13

相關問題