在WCF中发送大量数据时出现FaultException?

时间:2009-07-15 05:21:49

标签: wcf

我有一个很长的xml文件,文件内容如下:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
        <a:Action s:mustUnderstand="1">http://example.org/person</a:Action>
    </s:Header>
    <s:Body>
        <OrderDataBDO xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.datacontract.org/2004/07/BasWare.OM.BusinessDataObjects">
            <selected i:type="x:boolean" xmlns="">false</selected>
            <isSaved i:type="x:boolean" xmlns="">false</isSaved>
            <metadata i:nil="true" xmlns=""/>
            <hasUnsavedValues i:type="x:boolean" xmlns="">false</hasUnsavedValues>
            <hasChanged i:type="x:boolean" xmlns="">false</hasChanged>
            <defaultResourceId i:type="x:string" xmlns="">BWRc.OM.BUSINESSOBJECTS.ORDERDATABDO.ORDER_DATA</defaultResourceId>
            <_x0031_ xmlns:d4p1="http://schemas.datacontract.org/2004/07/BasWare.ProductFramework.BDOFramework" i:type="d4p1:ADate" xmlns="">
                <_x0031_ i:type="x:boolean">false</_x0031_>
                <_x0032_ i:type="x:boolean">false</_x0032_>
                <_x0033_ i:type="x:boolean">false</_x0033_>
                <_x0034_ i:nil="true"/>
                <_x0035_ i:type="x:boolean">true</_x0035_>
                <_x0036_ i:type="x:dateTime">1753-01-01T12:00:00</_x0036_>
                <_x0037_ i:type="x:string">d</_x0037_>
                <_x0038_ i:type="x:string">ActualDeliveryDate</_x0038_>
            </_x0031_>
            <_x0032_ xmlns:d4p1="http://schemas.datacontract.org/2004/07/BasWare.ProductFramework.BDOFramework" i:type="d4p1:AString" xmlns="">
                <_x0031_ i:type="x:boolean">false</_x0031_>
                <_x0032_ i:type="x:boolean">false</_x0032_>
                <_x0033_ i:type="x:boolean">false</_x0033_>
                <_x0034_ i:nil="true"/>
                <_x0035_ i:type="x:boolean">true</_x0035_>
                <_x0036_ i:type="x:string"/>
                <_x0037_ i:nil="true"/>
                <_x0038_ i:type="x:string">BuyerCode</_x0038_>
            </_x0032_>
            <_x0033_ xmlns:d4p1="http://schemas.datacontract.org/2004/07/BasWare.ProductFramework.BDOFramework" i:type="d4p1:AID" xmlns="">
                <_x0031_ i:type="x:boolean">false</_x0031_>
                <_x0032_ i:type="x:boolean">false</_x0032_>
                <_x0033_ i:type="x:boolean">false</_x0033_>
                <_x0034_ i:nil="true"/>
                <_x0035_ i:type="x:boolean">true</_x0035_>
                <_x0036_ i:type="x:string"/>
                <_x0037_ i:nil="true"/>
                <_x0038_ i:type="x:string">BuyerId</_x0038_>
            </_x0033_>
            <!--etc-->
            <_x0034_6 xmlns:d4p1="http://schemas.datacontract.org/2004/07/BasWare.ProductFramework.BDOFramework" i:type="d4p1:AMoney" xmlns="">
                <_x0031_ i:type="x:boolean">false</_x0031_>
                <_x0032_ i:type="x:boolean">false</_x0032_>
                <_x0033_ i:type="x:boolean">false</_x0033_>
                <_x0034_ i:nil="true"/>
                <_x0035_ i:type="x:boolean">true</_x0035_>
                <_x0036_ i:type="x:decimal">0</_x0036_>
                <_x0037_ i:type="x:string">N2</_x0037_>
                <_x0038_ i:type="x:string">TaxSum</_x0038_>
            </_x0034_6>
            <_x0034_7 xmlns:d4p1="http://schemas.datacontract.org/2004/07/BasWare.ProductFramework.BDOFramework" i:type="d4p1:AString" xmlns="">
                <_x0031_ i:type="x:boolean">false</_x0031_>
                <_x0032_ i:type="x:boolean">false</_x0032_>
                <_x0033_ i:type="x:boolean">false</_x0033_>
                <_x0034_ i:nil="true"/>
                <_x0035_ i:type="x:boolean">true</_x0035_>
                <_x0036_ i:type="x:string"/>
                <_x0037_ i:nil="true"/>
                <_x0038_ i:type="x:string">Text1</_x0038_>
            </_x0034_7>
            <_x0034_8 xmlns:d4p1="http://schemas.datacontract.org/2004/07/BasWare.ProductFramework.BDOFramework" i:type="d4p1:AString" xmlns="">
                <_x0031_ i:type="x:boolean">false</_x0031_>
                <_x0032_ i:type="x:boolean">false</_x0032_>
                <_x0033_ i:type="x:boolean">false</_x0033_>
            </_x0034_8>
        </OrderDataBDO>
    </s:Body>
</s:Envelope>

3 个答案:

答案 0 :(得分:2)

您需要设置各种设置 - 使用值,然后查看哪些工作。

首先,使用您正在使用的任何绑定并调整<readerQuotas>(maxStringContentLength,maxArrayLength,maxNameTableCharCount) - 如果可行,那很好!

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="LargeMessages">
          <readerQuotas maxDepth="32"
            maxStringContentLength="2147483647"
            maxArrayLength="2147483647"
            maxBytesPerRead="4096"
            maxNameTableCharCount="2147483647" />
        </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>

如果这不能解决您的问题,您需要在config中创建自己的自定义绑定,并在消息级别设置限制 - 如下所示:

  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="ExtraLargeMessages">
          <textMessageEncoding>
            <readerQuotas maxDepth="32"
              maxStringContentLength="2147483647"
              maxArrayLength="2147483647"
              maxBytesPerRead="4096"
              maxNameTableCharCount="2147483647" />
          </textMessageEncoding> 
          <httpsTransport 
              maxBufferPoolSize="1048576"
              maxReceivedMessageSize="1048576"
              maxBufferSize="1048576"/>
        </binding>
      </customBinding>
    </bindings>
  </system.serviceModel>

希望这有帮助。

马克

<强>更新
我会尝试将此行为添加到您的服务,然后再次调用该方法。

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="DetailedDebug" >
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="yourService" behaviorConfiguration="DetailedDebug">
        .....
      </service>
    </services>
  </system.serviceModel>

您现在应该在您的客户端获得详细的异常信息 - 您能告诉我们它是什么吗?也许这是完全不同的东西.......

马克

答案 1 :(得分:0)

将客户端和服务器上的Max Message Size(例如,取决于您的绑定)更改为described here

其他可能出错的地方。您可以enable tracing使用WCF并使用trace log viewer来缩小例外范围吗?

答案 2 :(得分:0)

也许这是对象的数量:尝试添加类似的东西

  <serviceBehaviors>
    <behavior name="PutTheNameOfYourBehaviorHere">
      <dataContractSerializer maxItemsInObjectGraph="10000000" />
    </behavior>
  </serviceBehaviors>

到你的配置文件。