2010-01-29 70 views
1

對於大於64K的郵件,我收到了maxreceivedmessagesize錯誤。問題是我已經改變了服務器和客戶端的一切,並沒有解決問題。silverlight 3 wcf服務配置 - 獲取maxreceivedmessagesize錯誤

這裏是我的服務器上的web.config文件,然後Silverlight客戶端配置:

<system.serviceModel> 
    <bindings> 
    <basicHttpBinding> 
     <binding name="secureobjectbind" maxBufferSize="2147483647" 
      maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
      maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
      maxNameTableCharCount="2147483647" /> 
     <security mode="Transport" /> 
     </binding> 
    </basicHttpBinding> 
    </bindings> 
    <behaviors> 
    <serviceBehaviors> 
     <behavior name="GiveWeb.Services.ShopBehavior"> 
     <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
     <dataContractSerializer maxItemsInObjectGraph="6553600" /> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
    <services> 
    <service behaviorConfiguration="GiveWeb.Services.ShopBehavior" 
     name="GiveWeb.Services.Shop"> 
     <endpoint address="" binding="basicHttpBinding" 
      bindingConfiguration="secureobjectbind" 
      contract="GiveWeb.Services.IShop"> 
     <identity> 
      <dns value="localhost" /> 
     </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpsBinding" 
     contract="IMetadataExchange" /> 
    </service> 
    </services> 
    <serviceHostingEnvironment> 
    <baseAddressPrefixFilters> 
     <clear/> 
     <add prefix="http://www.ushop2give.com"/> 
    </baseAddressPrefixFilters> 
    </serviceHostingEnvironment> 
</system.serviceModel> 

Silverlight客戶端

<configuration> 
    <system.serviceModel> 
     <bindings> 
      <basicHttpBinding> 
       <binding name="BasicHttpBinding_IShop" maxBufferSize="2147483647" 
        maxReceivedMessageSize="2147483647"> 
        <security mode="Transport" /> 
       </binding> 
      </basicHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="https://web14.ai-host.com/Services/Shop.svc" 
       binding="basicHttpBinding" 
       bindingConfiguration="BasicHttpBinding_IShop" 
       contract="ShopSVC.IShop" name="BasicHttpBinding_IShop" /> 
     </client> 
    </system.serviceModel> 
</configuration> 

所以爲什麼我仍然得到錯誤?


好吧,這裏爲後somemore信息...

我發現了一個錯誤。我的綁定對象的原始聲明是System.ServiceModel.Channels.Binding而不是System.ServiceModel.BasicHttpBinding。這就是爲什麼我沒有在對象上看到MaxReceivedMessageSize的屬性。

我糾正了這一點,並創建了一個函數來創建我的代理,但是當返回消息中超過65536字節時,仍然收到錯誤消息。

 public static ShopSVC.ShopClient ShopClientProxy() 
{ 
    System.ServiceModel.EndpointAddress lxAddress = new System.ServiceModel.EndpointAddress(new Uri(Application.Current.Host.Source, "../Services/Shop.svc")); 

    System.ServiceModel.BasicHttpBinding lxBinding = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.Transport); 
    lxBinding.MaxReceivedMessageSize = 2147483647; 
    lxBinding.MaxBufferSize = 2147483647; 
    lxBinding.ReceiveTimeout = new TimeSpan(0, 5, 0); 

    return new GiveSL.ShopSVC.ShopClient(lxBinding, lxAddress); 
} 
+0

你能發佈你收到的確切錯誤信息嗎? – Jacob 2010-01-29 18:22:12

+0

System.ServiceModel.CommunicationException:傳入消息的最大消息大小配額(65536)已被超出。要增加配額,請在適當的綁定元素上使用MaxReceivedMessageSize屬性。 – 2010-01-29 20:13:04

+0

也許你的服務沒有使用你定義的行爲。您可以將服務定義和端點添加到帖子中嗎? – Jacob 2010-01-29 21:42:19

回答

0

最後的解決方案......

有兩個潛在的問題:

  1. 在客戶端的綁定對象被錯誤地宣佈爲System.ServiceModel.Channels.Binding,應該已被定義爲System.ServiceModel.BasicHttpBinding。所以,上面列出的函數是在Silverlight客戶端中創建代理對象的正確代碼。
  2. 它必須是應用程序緩存對服務客戶端的第一個調用。所有這一次,我一直在努力工作的解決方案,我只是改變了一個綁定調用,並不是我的項目中調用的第一個。當我編寫用於創建代理對象的中心函數時,直到我將所有代碼都更改爲使用該中心函數時,它仍然不起作用。

既然我所有的代碼都使用了相同的函數來創建服務客戶端代理,那麼MaxReceivedMessageSize的設置就會受到尊重,並且一切正常。

哇...只是從來沒有看到過這一個。

感謝大家(特別是雅各布)在這一個懸掛着我。

Steve

1

如果該服務在ASP.NET主持過程中,你還需要確保Web服務器的最大請求長度允許該大小的消息。例如:

<configuration> 
    <system.web> 
    <httpRuntime maxRequestLength="2147483647" /> 
    </system.web> 
</configuration> 
+0

我將你的標籤添加到我的web.config文件中。我得到一個錯誤,因爲那對於那個領域來說太大了,所以我把它設置爲max:maxRequestLength =「2097151」。但我仍然收到錯誤。 僅供參考,我正在下載圖片,因此我知道圖片的大小可能大於64Kb,但不會超過2GB。那些小於64Kb的圖片工作得很好。 – 2010-01-29 20:16:12

0

一切看起來都很好,所以我不知道這是否簡單。您正在更改配置的服務器是否與Silverlight客戶端指向https://web14.ai-host.com/Services/Shop.svc的配置相同?另外,您可能希望嘗試將完全相同的綁定配置從服務器配置粘貼到客戶端的綁定配置。

+0

服務器是一樣的。 我試着將綁定設置複製到silverlight客戶端文件,但標籤不是全部允許的(正如我在其他評論中提到的那樣)。 – 2010-01-30 20:24:26

0

好的,這裏是另一個嘗試。 Silverlight 2的某些版本沒有正確讀取ClientConfig,所以通過代碼在客戶端綁定上設置MaxReceivedMessageSize來解決此問題。也許Silverlight 3有類似的問題。你可以嘗試通過代碼設置MaxReceivedMessageSize嗎?請參閱http://forums.silverlight.net/forums/t/11313.aspx

+0

我試圖設置這些,但它們不是silverlight客戶端中basicHttpBinding對象的可用屬性。 – 2010-02-09 23:13:12

+0

當然可以。當我說通過代碼設置時,我不是指配置文件中的XML。 MaxReceivedMessageSize的API參考位置在以下位置:http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpbinding.maxreceivedmessagesize(VS.95).aspx – Jacob 2010-02-09 23:25:48

+0

我的客戶端使用以下代碼進行設置,以創建一個方法調用: lxAddress = new System.ServiceModel.EndpointAddress(new Uri(Application.Current.Host.Source,「../Services/Shop.svc」)); lxBinding = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.Transport); lxProxy = new GiveSL.ShopSVC.ShopClient(lxBinding,lxAddress); lxBinding對象沒有「MaxReceivedMessageSize」屬性。我正在使用VS的Web Express版本。我希望這不是問題。 – 2010-02-10 14:33:35