4

我有一个 WCF Web 方法,它将 XElement 对象作为参数。对于我的一个 XML 文件(大小为 600KB 左右),这工作得很好,但是,对于这个更大的 XML 文件(大约 5MB),我立即得到一个 CommunicationException。

我已经增加了绑定的消息大小。下面是我的 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>

提前致谢!

4

4 回答 4

1

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

有关详细信息,请参阅:http: //msdn.microsoft.com/en-us/library/ms731325.aspx http://forums.silverlight.net/forums/p/88704/205040.aspx

Update: Can you try to increase the maxAllowedContentLength as described here: http://social.msdn.microsoft.com/Forums/en/wcf/thread/e6e21132-ad3f-4135-8ab9-77923b099907

于 2010-08-06T18:40:41.137 回答
1

Maybe your XElement has too many nodes/child elements, and you need to set the maxItemsInObjectGraph attribute under dataContractSerializer to something larger?

于 2010-08-12T22:47:20.740 回答
1

try to add following snippet into your web.config for the service application:

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

When you host the service in web server you also have to tweak allowed request size for the web server.

Best regards, Ladislav

于 2010-08-14T20:31:14.183 回答
0

Do you know how to turn off VS host and to just deploy to IIS and give it a ping. Normal IIS 7 on your dev box will do just fine. You can still attach debugger etc, just won't have instantaneous F5 gratification but since your ocode is not dying on startup you don't need to see if from the fist line anyway :-)

If you would need to attach very early you could could make a mimimal method that doesn't tounch anything at all and just returns int constnat - just to bring up app pool so you can attach.

于 2010-08-14T03:39:34.547 回答