2012-03-08 32 views
0

我看過很多解決方案來解決我的問題,但我沒有找到對我有用的任何東西。用web服務發送一個大陣列

我的問題很簡單:我無法通過webservice發送長字節數組。我可以發送一個代表4千字節但沒有更大的圖像的數組。

這是客戶端配置

<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贏得」不接受它,說它只接受安全節點。

有人說在客戶端配置中更改transfermode會解決問題,但我只能使用緩衝模式,它不接受其他任何東西。

我用過fiddler,它說程序超過了maxarraylength,你可以看到我在web.config中改變了這個值,但是我不能在客戶端配置中更改,因爲它表示綁定節點沒有readerquotas屬性。

回答

0

只是嘗試創建新配置文件以下Maximum array length quota(解決我的問題),看看它是否解決您的問題或沒有,因爲我認爲這個問題是由於您的配置文件。

+0

的問題是在客戶端配置,因爲我不能添加readerquotas,我已經試圖再次創造配置文件,但沒有任何變化,我已經創建了一個新的虛擬項目,看看我是否可以將rederquotas添加到客戶端配置,但我再也不能這樣做 – zizzi 2012-03-14 08:24:24

+0

是的,我遇到了同樣的情況。 .ClientConfig似乎與應用程序或web.config文件不同。任何方案? – 2012-10-22 08:09:40

0

我想你需要在客戶端上設置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> 
+0

正如我在我的第一篇文章中所說,我不能在客戶端配置中添加readerquotas,至於dataContractSerializer,我已經將它添加到web.config中,並且我給它提供了maxint值 – zizzi 2012-03-14 08:16:55

+0

默認情況下VS2010會創建readerquotas,當我添加一個新的服務參考,所以這絕對有可能。 – Andreas 2012-03-14 16:03:39

+0

我知道,但是當我創建或更新服務引用,我可以在clientconfig maxBufferSize maxReceivedMessageSize中找到預期的,但我無法找到readerquotas,即使我在web.config中創建它們,如果你想我也可以做一個截圖您可以看到我無法在客戶端配置中創建readerquotas – zizzi 2012-03-14 16:08:42