简体   繁体   中英

Send a large array with a webservice

i've looked to a lot of solutions to resolve my problem but i didn't found anything good for me.

my problem is simple: i can't send a long array of bytes through the webservice. I can send an array that represents an image of 4 Kbytes but nothing bigger.

this is the client configuration

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

this is the server 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>

I've read solutions where somebody said to put the readerquotas also in the client config but the xml won't accept it, saying that it accepts only security nodes.

Somebody says that changing the transfermode in the client config will resolve the problem, but i can use only the buffered mode it doesn't accept anything else.

I've used fiddler and it says that the program exceeds the maxarraylength, as you can see I've changed this value in the web.config but i can't change in the client config because it says that the binding node doesn't have the readerquotas property.

只需尝试按照最大阵列长度配额 (解决了我的问题)创建新的配置文件,然后查看它是否可以解决您的问题,因为我认为问题是由于您的配置文件所致。

I think you need an endpoint behavior configuration on the client that sets the DataContractSerializer's maxItemsInObjectGraph property. You should also add the readerQuotas to your client's binding configuration. This should work:

Client:

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

Server:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM