开发者

bug when try to send file in wcf

when I tried to send file using WCF service I get this exception

The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'Send_File'. The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.

I converted the file at first to array of Bytes before I sent it this is client configuration who sent the file

<system.serviceModel>
<bindings>
  <netTcpBinding>
    <binding name="TcpBinding" closeTimeout="10:00:00" openTimeout="10:00:00"
        receiveTimeout="10:00:00" sendTimeout="10:00:00" transactionFlow="false"
        transferMode="Buffered" transactionProtocol="OleTransactions"
        hostNameComparisonMode="StrongWildcard" listenBacklog="10"
        maxBufferPoolSize="10000000" maxBufferSize="10000000" maxConnections="30"
        maxReceivedMessageSize="10000000">
      <readerQuotas maxDepth="64" maxStringContentLength="10000000" maxArrayLength="100000000"
          maxBytesPerRead="10000000" maxNameTableCharCount="10000000" />
      <reliableSession ordered="true" inactivityTimeout="10:00:00"
          enabled="false" />
    </binding>
  </netTcpBinding>
  <wsDualHttpBinding>
    <binding name="HttpBinding" closeTimeout="1开发者_StackOverflow社区0:00:00" openTimeout="10:00:00"
        receiveTimeout="10:00:00" sendTimeout="10:00:00" bypassProxyOnLocal="false"
        transactionFlow="false" hostNameComparisonMode="StrongWildcard"
        maxBufferPoolSize="10000000" maxReceivedMessageSize="10000000"
        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="10000000" maxArrayLength="10000000"
          maxBytesPerRead="10000000" maxNameTableCharCount="10000000" />
      <reliableSession ordered="true" inactivityTimeout="10:00:00" />
    </binding>
  </wsDualHttpBinding>
</bindings>
<behaviors>
  <endpointBehaviors>
    <behavior name="filebehavior">
      <dataContractSerializer maxItemsInObjectGraph="2000000000"/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<client>
  <endpoint address="net.tcp://localhost:8000/ChatRoom/service" behaviorConfiguration="filebehavior"
      binding="netTcpBinding" bindingConfiguration="TcpBinding"
      contract="ChatRoom" name="TcpBinding">
    <identity>
      <servicePrincipalName value="my_machine\ASPNET" />
    </identity>
  </endpoint>
  <endpoint address="http://localhost:8001/ChatRoom/service" binding="wsDualHttpBinding"
      bindingConfiguration="HttpBinding" contract="ChatRoom" name="HttpBinding">
    <identity>
      <servicePrincipalName value="my_machine\ASPNET" />
    </identity>
  </endpoint>
</client>

server configration

<system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="securingWSHttpBinding">
        </binding>
        <binding name="wsHttpBinding_ChatRoomServices" maxReceivedMessageSize="10000000" />
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceTimeouts transactionTimeout="10:00:00"/>
          <serviceMetadata httpGetEnabled="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
        <services>
      <service name="ChatRoomService.ChatRoom"
               behaviorConfiguration="ServiceBehavior">
        <endpoint address="service" binding="netTcpBinding" contract="ChatRoomService.IChatRoom" name="TcpBinding"/>
        <endpoint address="service" binding="wsDualHttpBinding" contract="ChatRoomService.IChatRoom" name="HttpBinding"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" name="MexBinding"/>
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8000/ChatRoom/"/>
            <add baseAddress="http://localhost:8001/ChatRoom/"/>
          </baseAddresses>
        </host>
      </service>
        </services>
    </system.serviceModel>

how I can solve this exception ?


Add this when specifying the service behavior, and endpoint behavior

on the client side, when you specify the endpoint, set the behavior name:

<endpoint behaviorConfiguration = "myBehavior"/>

and then specify this behavior:

<behaviours>
    <endpointBehaviors>
        <behavior name="myBehavior">
            <dataContractSerializer maxItemsInObjectGraph="a number that is big enough"/>
        </behavior>
    </endpointBehaviors>
</behaviors>

on the server:

when you specify the 'service' and the 'endpoint', attach a serviceBehavior and endpointBehavior respectively, as for the client.


First off, your bindings don't even match between the client and the server :)

Your client has a NetTcpBinding and a DualWsHttpBinding, and your server has a wsHttpBinding. i'm surprised they can even communicate to each other, to be honest. (Unless you're using WCF 4.0, in which case you will have default bindings and endpoints).

Secondly, your service config file isn't referencing the delared binding - there is no bindingConfiguration attribute on the endpoints, so if communication is established the channel will use the default values for the specified binding protocol.

The client configuration looks ok, try this for the server (I'm only including the NetTcpBinding protocol, and adding the behaviorName and bindingConfiguration attributes to the endpoint - the other bindings would be similar):

<system.serviceModel>
  <bindings>
    <netTcpBinding>
      <binding name="TcpBinding" closeTimeout="10:00:00" openTimeout="10:00:00" receiveTimeout="10:00:00" sendTimeout="10:00:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="10000000" maxBufferSize="10000000" maxConnections="30" maxReceivedMessageSize="10000000">
        <readerQuotas maxDepth="64" maxStringContentLength="10000000" maxArrayLength="100000000" maxBytesPerRead="10000000" maxNameTableCharCount="10000000" />       
        <reliableSession ordered="true" inactivityTimeout="10:00:00" enabled="false" />     
      </binding>
    </netTcpBinding>
  </bindings> 
  <behaviors>
    <endpointBehaviors>
      <behavior name="filebehavior">       
        <dataContractSerializer maxItemsInObjectGraph="2000000000"/>     
      </behavior>
    </endpointBehaviors> 
  </behaviors> 
  <service>
    <endpoint address="net.tcp://localhost:8000/ChatRoom/service" behaviorConfiguration="filebehavior" binding="netTcpBinding" bindingConfiguration="TcpBinding" contract="ChatRoom" name="TcpBinding">
      <identity>
        <servicePrincipalName value="my_machine\ASPNET" />
      </identity>
    </endpoint>    
  </service>
</system.serviceModel>


you may want to try Streamed transfer mode in your case. http://msdn.microsoft.com/en-us/library/ms789010.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜