2011-11-07 51 views
0

我搜索並嘗試了所有以前發佈的建議解決方案,並沒有任何運氣。我顯然做錯了,我只是無法弄清楚,我希望有人能夠幫助我here.My問題是這樣的:我有一個WCF服務和一個WCF客戶端。當我調用服務並嘗試傳遞一個字節數組(將圖像上傳到服務)時,我得到一個非常模糊的Target Invokation異常錯誤。所以,我迷上了跟蹤並且跟蹤日誌告訴我消息配額大小超過了限制,但我已經修改了兩端的配置(app.config & web.config)以包含一個非常大的限制。問題是,它告訴我超過了65536的限制,但正如你從我的配置下面可以看到的那樣大於這個數量,所以就好像我的客戶端正在使用一些其他配置值,或者我沒有配置它是正確的,它忽視了我擁有的東西。有人能幫我嗎?如何將圖像數據發送到WCF服務

App.Config中: enter image description here

的Web.Config: enter image description here

你們可以提供任何幫助將不勝感激。我一直在這個問題上停留兩天。

謝謝大家。

這裏的實際配置代碼:

<system.serviceModel> 
    <bindings>    
     <wsHttpBinding> 
      <binding name="WSHttpBinding_IDataSyncService" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
       maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 
       messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
       allowCookies="false"> 
       <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
       <reliableSession ordered="true" inactivityTimeout="00:10:00" 
        enabled="false" /> 
       <security mode="Message"> 
        <transport clientCredentialType="Windows" proxyCredentialType="None" 
         realm="" /> 
        <message clientCredentialType="Windows" negotiateServiceCredential="true" 
         algorithmSuite="Default" /> 
       </security> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost/DataSyncWCF/DataSyncService.svc" 
      binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDataSyncService" 
      contract="IDataSyncService" name="WSHttpBinding_IDataSyncService"> 
      <identity> 
       <dns value="localhost" /> 
      </identity> 
     </endpoint> 
    </client> 
</system.serviceModel> 

的Web.Config:

<services> 
    <service behaviorConfiguration="DataSyncWCF.Service1Behavior" 
    name="DataSyncWCF.DataSyncService"> 
    <endpoint address="" binding="wsHttpBinding" bindingName="WSHttpBinding_IDataSyncService" 
     contract="DataSyncWCF.IDataSyncService"> 
     <identity> 
     <dns value="localhost" /> 
     </identity> 
    </endpoint> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 
</services> 
<bindings>  
    <wsHttpBinding> 
    <binding name="DataSyncWCF.Service1Binding" maxBufferPoolSize="2147483647" 
     maxReceivedMessageSize="2147483647" allowCookies="true"> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
     maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     <security mode="None">    
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="DataSyncWCF.Service1Behavior">   
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

這裏是我的代碼調用WCF服務:在WCF

VehicleImage vi = new VehicleImage(); 
System.IO.FileStream fs = new System.IO.FileStream(@"C:\images\1FAHP35N18W1589_01.jpg",  System.IO.FileMode.Open, System.IO.FileAccess.Read); 
int len = (int)fs.Length; 
vi = new VehicleImage(); 
vi.Image = new Byte[len];    
fs.Read(vi.Image, 0, len); 

// Here's the call to the WCF Service. It never makes it to the Service because of the message size limit error. 
ResponseContract rc = client.SyncImage(vi); 
+2

你嘗試更改配置文件後,重新啓動服務器?另外,你有沒有嘗試發送小於65K的圖像?那將是一個開始的好地方。 –

+0

提示:使用正確的格式('{}'按鈕)將文本代碼(也就是XML)作爲文本進行發佈。使搜索等更容易。 –

+0

@Paul Sasik我確實嘗試發送小於65k的小圖片,並且確實有效。問題是,我將要發送大約90 - 120K的圖像大小。 –

回答

4

一切都在很大程度上限制(扼殺),有理由。

我在配置中看到很多2G號碼,這通常不是一個好主意。你可能錯過了一些,我不能很快發現SerializationLimit(大約名字)。

有兩種基本方式可以處理WCF中的大消息:MTOM和流式傳輸。

+0

是的,由於我收到的錯誤,我只把這些數值提高了。我把這個數字增加到了這麼高的價值,看看是否可以解決這個問題,然後我知道我有了一個解決方案後就會反過來減少它。我已經嘗試過MTOM,也沒有改變結果。 –

+0

我會考慮一個Stream。易於使用,它表現了無論如何需要的流式(異步)行爲。 –

1

在你的web.config的wsHttpBinding,設置maxReceivedMessageSize

<binding name="www" maxReceivedMessageSize="2147483647"> 
+0

是的,我已在客戶端配置和web.config中設置了該值。 –

+2

您可以添加您收到的確切錯誤消息嗎?這將幫助我們確定需要更改的配置(fyi:我們通過WCF成功傳輸非常大(> 1GB)的文件,因此不存在固有問題)。 –