2010-08-06 65 views
4

我有一個WCF Web MEthod,它接受一個XElement對象作爲參數。對於我的一個XML文件(大小爲600KB左右),這很好,但是,對於這個更大的XML文件(大約5MB),我立即得到一個CommunicationException。由於參數大小導致的WCF服務通信異常

我已經增加了我的綁定的消息大小。下面是我的web.config的ServiceModel部分:

<system.serviceModel> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="BIMIntegrationWS.metadataBehavior"> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
    </behavior> 
    <behavior name=""> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors>   

<bindings> 
    <customBinding>   
    <binding name="BIMIntegrationWS.IntegrationService.customBinding0" 
     closeTimeout="00:01:00" openTimeout="00:01:00" 
     receiveTimeout="00:10:00" sendTimeout="00:10:00"> 
     <binaryMessageEncoding> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
         maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     </binaryMessageEncoding> 
     <httpTransport maxBufferPoolSize="2147483647" maxBufferSize="2147483647" 
         maxReceivedMessageSize="2147483647" /> 
    </binding> 
    </customBinding> 
</bindings> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
<services>  
    <service name="BIMIntegrationWS.BIMIntegrationWS" behaviorConfiguration="BIMIntegrationWS.metadataBehavior"> 
    <endpoint address="" binding="customBinding" bindingConfiguration="BIMIntegrationWS.IntegrationService.customBinding0" 
    contract="BIMIntegrationWS.IBIMIntegrationService" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 
</services> 
</system.serviceModel> 

在客戶端,我ClientConfig看起來是這樣的:

<system.serviceModel>  
     <bindings> 
      <customBinding>     
        <binding name="CustomBinding_IBIMIntegrationService"> 
        <binaryMessageEncoding /> 
        <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />          
        </binding> 
      </customBinding> 
     </bindings>   
    <client>   
     <endpoint address="http://localhost:1895/IntegrationService.svc" 
      binding="customBinding" bindingConfiguration="CustomBinding_IBIMIntegrationService" 
      contract="BIMIntegrationService.IBIMIntegrationService" name="customBindingEndpoint" /> 
    </client> 
</system.serviceModel> 

提前感謝!

+0

能否請您發佈細節的CommunicationException? – larsw 2010-08-06 18:14:56

+0

詳細說明:「System.ServiceModel.CommunicationException未被用戶代碼處理。Message =遠程服務器返回錯誤:NotFound。」 – Overhed 2010-08-06 18:18:46

+0

你在IIS下託管服務嗎? – larsw 2010-08-06 18:26:05

回答

1

嘗試下面的代碼片段添加到您的web.config文件服務應用程序:

<system.web> 
    <httpRuntime maxRequestLength="16384" /> <!-- 16MB --> 
    </system.web> 

當你在託管Web服務器的服務,您也必須調整允許請求大小爲Web服務器。

最好的問候,拉吉斯拉夫·

+1

+1 原始問題中的調試信息不​​足,但我認爲這可能是您正在運行的對象,因爲默認最大傳入請求在IIS中限制爲4096 KB。由於您試圖將5MB的XML推送到服務器 - 繁榮! 原始海報是否嘗試在Windows服務中自行託管應用程序,而不是在IIS下?如果您在Intranet環境中運行此應用程序,我會建議使用net.tcp綁定進行自我管理以提高性能,因爲您正在推送大量數據。 – 2010-08-15 18:25:39

+0

這似乎已經成功了。非常感謝Laidslav!賞金過期了,所以我不得不重新添加它。我會盡快給予獎勵(23小時)。 再次感謝! – Overhed 2010-08-16 14:13:51

1

您可能需要更改<readerQuotas />子元素<binaryMessageEncoding />的屬性值。

欲瞭解更多信息,請參見: http://msdn.microsoft.com/en-us/library/ms731325.aspx http://forums.silverlight.net/forums/p/88704/205040.aspx

更新: 你可以嘗試增加maxAllowedContentLength如下所述: http://social.msdn.microsoft.com/Forums/en/wcf/thread/e6e21132-ad3f-4135-8ab9-77923b099907

+0

手動設置屬性屬性並不值得。 :\ 我正在更新包含這些問題的web.config。 – Overhed 2010-08-06 19:00:27

+0

好吧,你也可以嘗試調整元素的值:http://msdn.microsoft.com/en-us/library/bb924506.aspx – larsw 2010-08-06 19:13:45

+0

任何提示我將如何去調整值XElement類型(或者任何其他已經可以Serializable的類型)? – Overhed 2010-08-06 20:57:00

1

也許你的XElement有太多的節點/子元素,並且您需要將dataContractSerializer下的maxItemsInObjectGraph屬性設置爲更大的值?

0

你知道如何關閉VS主機,只是部署到IIS並給它一個ping。你的開發箱上的正常IIS 7將會很好。你仍然可以附加調試器等,只是不會有瞬間的F5滿足,但因爲你的ocode沒有在啓動時死亡,所以無論如何都不需要看第一行:-)

如果你需要附加很早以前,你可以製作一個不會觸及任何東西的簡單方法,只需返回int constnat - 只需調出應用程序池,以便附加即可。

相關問題