由于参数大小导致WCF服务通信异常

发布于 2024-09-13 05:11:21 字数 2921 浏览 10 评论 0原文

我有一个 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>

提前致谢!

I've got a WCF Web MEthod that takes in an XElement object as a parameter. For one of my XML files (sized at 600KB or so) this works just fine, however, for this bigger XML file (about 5MB) I get a CommunicationException right away.

I've already increased the message sizes for my binding. Below is the ServiceModel section of my web.config:

<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>

On the client, my ClientConfig looks like this:

<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>

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

中性美 2024-09-20 05:11:21

尝试将以下代码片段添加到服务应用程序的 web.config 中:

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

当您在 Web 服务器中托管服务时,您还必须调整 Web 服务器允许的请求大小。

此致,
拉迪斯拉夫

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

杯别 2024-09-20 05:11:21

也许您的 XElement 有太多节点/子元素,并且您需要将 dataContractSerializer 下的 maxItemsInObjectGraph 属性设置为更大的值?

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

别再吹冷风 2024-09-20 05:11:21

您可能需要更改 子元素的属性值。

有关更多信息,请参阅:
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

You probably need to change the values of the attributes of the <readerQuotas /> sub element of <binaryMessageEncoding />.

For more information, see:
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

眉目亦如画i 2024-09-20 05:11:21

您知道如何关闭 VS 主机并部署到 IIS 并对其进行 ping 操作吗?你的开发机上的普通 IIS 7 就可以了。您仍然可以附加调试器等,只是不会立即获得 F5 满足感,但由于您的 ocode 不会在启动时死亡,因此您不需要从第一行查看是否:-)

如果您需要很早就附加,您可以可以创建一个最小的方法,根本不接触任何东西,只返回 int constnat - 只是为了启动应用程序池,以便您可以附加。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文