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

编程入门 行业动态 更新时间:2024-10-20 13:50:49
本文介绍了由于参数大小导致 WCF 服务通信异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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.

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

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>

在客户端上,我的 ClientConfig 如下所示:

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>

提前致谢!

推荐答案

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

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

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

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

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

最好的问候,拉迪斯拉夫

Best regards, Ladislav

这篇关于由于参数大小导致 WCF 服务通信异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 19:39:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141132.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   大小   参数   通信   WCF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!