【问题标题】:Send a large array with a webservice发送带有 web 服务的大型数组
【发布时间】:2012-03-08 08:54:00
【问题描述】:

我已经寻找了很多解决方案来解决我的问题,但我没有找到任何对我有好处的方法。

我的问题很简单:我无法通过网络服务发送长字节数组。我可以发送一个代表 4 KB 图像的数组,但不会更大。

这是客户端配置

    <configuration>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_ICespitiAVService"                              closeTimeout="02:00:00"
                openTimeout="02:00:00" receiveTimeout="02:00:00" sendTimeout="02:00:00"         maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" >
                        <security mode="None" />
                    </binding>
                </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost:51366/CespitiAVService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICespitiAVService"
            contract="CespitiAVService.ICespitiAVService" name="BasicHttpBinding_ICespitiAVService"/>
            </client>
        </system.serviceModel>
    </configuration>

这是服务器配置

      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="BasicHttpBinding" maxBufferSize="2147483647"
           maxReceivedMessageSize="2147483647">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
           maxArrayLength="2147483647" maxBytesPerRead="2147483647"
           maxNameTableCharCount="2147483647" />
            </binding>
          </basicHttpBinding>
        </bindings>
          <client />
          <behaviors>
            <serviceBehaviors>
              <behavior name="">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
                <dataContractSerializer maxItemsInObjectGraph="655360"/>
             </behavior>
            </serviceBehaviors>
          </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
      </system.serviceModel>

我读过一些解决方案,有人说要将 readerquotas 也放在客户端配置中,但 xml 不接受它,说它只接受安全节点。

有人说在客户端配置中更改传输模式可以解决问题,但我只能使用缓冲模式,它不接受任何其他内容。

我使用了 fiddler,它说程序超出了 maxarraylength,如您所见,我在 web.config 中更改了此值,但我无法在客户端配置中更改,因为它说绑定节点没有 readerquotas 属性。

【问题讨论】:

    标签: .net arrays web-services configuration


    【解决方案1】:

    只需尝试在Maximum array length quota 之后创建新的配置文件(解决了我的问题),看看它是否解决了您的问题,因为我认为问题是由于您的配置文件造成的。

    【讨论】:

    • 问题出在客户端配置中,因为我无法添加 readerquotas,我已经尝试再次创建配置文件但没有任何变化,我创建了一个新的虚拟项目来查看是否我可以将 rederquotas 添加到客户端配置中,但我还是不能这样做
    • 是的,我正在经历同样的事情。 .ClientConfig 似乎与 app 或 web.config 文件不同。有什么解决办法吗?
    【解决方案2】:

    我认为您需要在设置 DataContractSerializer 的 maxItemsInObjectGraph 属性的客户端上进行端点行为配置。您还应该将 readerQuotas 添加到客户端的绑定配置中。这应该有效:

    客户:

    <behaviors>
      <endpointBehaviors>
        <behavior name="ICespitiAVService_Behavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ICespitiAVService" closeTimeout="02:00:00"
          openTimeout="02:00:00" receiveTimeout="02:00:00" sendTimeout="02:00:00"
          maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="32" maxArrayLength="2147483647" />
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:51366/CespitiAVService.svc"
        binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_ICespitiAVService"
        behaviorConfiguration="ICespitiAVService_Behavior"
        contract="CespitiAVService.ICespitiAVService"
        name="BasicHttpBinding_ICespitiAVService"/>
      </endpoint>
    </client>
    

    服务器:

    <bindings>
      <binding name="LargeMessages" maxReceivedMessageSize="2147483647">
        <readerQuotas maxArrayLength="2147483647" maxDepth="32" />
      </binding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ICespitiAVService.Behavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="ICespitiAVService.Behavior" name="ICespitiAVService">
        <endpoint address="" binding="basicHttpBinding"
          contract="CespitiAVService.ICespitiAVService"
          bindingConfiguration="LargeMessages"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:51366/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    

    【讨论】:

    • 正如我在第一篇文章中所说,我无法在客户端配置中添加 readerquotas,至于 dataContractSerializer,我已经将它添加到 web.config 中,并且我给了它 maxint 值
    • VS2010 在我添加新服务引用时默认创建 readerquotas,所以这绝对是可能的。
    • 我知道,但是当我创建或更新服务引用时,我可以按预期在 clientconfig maxBufferSize maxReceivedMessageSize 中找到,但即使我在 web.config 中创建它们,我也找不到 readerquotas 如果你想要我也可以做一个截图,这样你就可以看到我无法在客户端配置中创建 readerquotas
    • 即使documentation 也提到这是可能的。如果你不能这样做,你必须详细说明你得到了什么错误。您是否尝试过使用我发布的配置而不是您的配置?像复制和粘贴,编译和运行?当您说“我无法找到读者配额”时是什么意思?您希望在哪里“找到”它们?您是否尝试过在代码中创建绑定并将其传递给服务客户端构造函数?
    • 这就是我的意思img215.imageshack.us/img215/8065/immagine3yh.png 翻译:“元素“绑定”有一个无效的子元素“readerQuotas”。元素接受“安全”。我也尝试过代码,但它不接受。我也尝试复制和粘贴您的代码,但它给出了同样的问题
    猜你喜欢
    • 2017-05-30
    • 1970-01-01
    • 2016-12-28
    • 2015-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-31
    • 1970-01-01
    相关资源
    最近更新 更多