WCF - The maximum array length quota (16384) - wcf

When I receive files I receive this exception.
My client configuration:
<bindings>
<basicHttpBinding>
<binding name="basicHttpSecuredBinding"
maxReceivedMessageSize = "2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" sendTimeout="00:25:00" receiveTimeout="00:25:00">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="TransportWithMessageCredential">
<message clientCredentialType="Certificate"/>
</security>
</binding>
</basicHttpBinding>
Client endpoint
<client>
<!--TODO: currently configured to work with the staging for testing-->
<endpoint name="ep_SmtkSyncService"
address="https://1234.com/SyncService.svc"
binding="basicHttpBinding"
bindingConfiguration="basicHttpSecuredBinding"
behaviorConfiguration="transportWithClientCredentialsBehavior"
contract="SynerionHcm.Smtk.Domain.Common.Contracts.ISmtkSyncService" />
</client>
This exception has driven me crazy:
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.'. Please see InnerException for more details. ---> System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type

Related

The remote server returned an error: (413) Request Entity Too Large in WCF

WCF Service is returning
The remote server returned an error: (413) Request Entity Too Larg
but data size only 80KB i configured 2GB max size. I tried in stack overflow but still I am facing the same issue.
Configuration:
<service name="HP.VFS.ShoppingcartService.ShoppingCart">
<endpoint name="SOAPEndPoint" contract="HP.VFS.ShoppingcartService.IShoppingCart" binding="basicHttpBinding" address="soap" />
<endpoint name="RESTEndPoint" contract="HP.VFS.ShoppingcartService.IShoppingCart" binding="webHttpBinding" address="api" behaviorConfiguration="restbehavior" /> <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
<basicHttpBinding>
<binding name="basicHttpBinding" closeTimeout="10:00:00" receiveTimeout="10:00:00" sendTimeout="10:00:00">
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
<binding name="soap" closeTimeout="10:00:00" receiveTimeout="10:00:00" sendTimeout="10:00:00" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
Server Side Interface
[OperationContract(Name = "wstCreateOrder")]
[FaultContract(typeof(ApplicationFault))]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped,UriTemplate = "/wstCreateOrder/OrderInfo")]
string CreateOrder(string OrderInfo);
In client side
Service.CreateOrder(80+ KB string);
I am accessing WCF service for transferring data via SOAP protocol inside MVC4 .Net application. Parameter all are string type. While calling the method if the text size is more than 60 KB it's throwing an error like "The remote server returned an error: (413) Request Entity Too Larg". But in Server configuration based on stackoverflow guidelines i added MAX size for Max message received in Configuration still am facing the same kindly help me.
Thanks for all. finally i got the solution. solution is just increasing the size for maxDepth "2000000" to "2147483647" problem solved.

WCF- Duplex connection (hosted in IIS)

I have a full duplex, I run successfully in my local machine.
I host it in my server (IIS - server 2008 R2-STANDARD), and trying to connect, as following:
this.myCallbackProxy = new MyCallbackProxy();
InstanceContext cntx = new InstanceContext(myCallbackProxy);
this.Proxy = new MyServiceClientProxy(cntx, "WSDualHttpBinding_I_BridgeWCFService");
this.Proxy.ClientCredentials.Windows.ClientCredential.UserName = "YY";
this.Proxy.ClientCredentials.Windows.ClientCredential.Password = "PP";
Now, when I try to call an API, I stuck until time out.
I tried to configure the WCF in the IIS to connect as specific user , but then when I try to call an API from my client, I get the following exception:
"The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response"
I must mention that I have another WCF hosted in same IIS, with same user (server user name), and it works perfect. (I create another (similar) application poll for the duplex WCF)
My config file:
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_I_BridgeWCFService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483646" maxReceivedMessageSize="2147483646"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483646"
maxArrayLength="2147483646" maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"/>
<security mode="None">
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://xx.xx.xx.xx/_Bridge/_BridgeWcfService.svc"
binding="wsDualHttpBinding"
bindingConfiguration="WSDualHttpBinding_I_BridgeWCFService"
contract="_BridgeWcfServiceReference.I_BridgeWCFService"
name="WSDualHttpBinding_I_BridgeWCFService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</client>

The max message size quota for incoming messages (65536) ....To increase the quota, use the MaxReceivedMessageSize property

I got this crazy problem I'm trying to deal with. I know that when we're getting huge amount of data we must increase the quota on client .config file, but what am I supposed to do if my client is sending huge data "to" the WCF server?
It works perfectly normal when I'm sending small sized input parameter. Unfortunately, it breaks down when the input grows bigger.
Debugger it says:
Bad Request, 400;
on trace file it is:
The maximum message size quota for incoming messages (65536) has
been exceeded. To increase the quota, use the MaxReceivedMessageSize
property on the appropriate binding element.
Is there some way to increase this quota of incomming data on the server side? if so, how?
Here's my sample config related parts:
<bindings>
<basicHttpBinding>
<binding name="MyBasicHttpBinding"
closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="MyWcfService">
<endpoint address="http://myservice..."
binding="basicHttpBinding" bindingConfiguration="MyBasicHttpBinding"
name="MyBasicHttpBinding" contract="IMyContract" />
</service>
</services>
and here's my client-side code (I create it dynamically):
var binding = new BasicHttpBinding();
binding.MaxBufferPoolSize = 2147483647;
binding.MaxBufferSize = 2147483647;
binding.MaxReceivedMessageSize = 2147483647;
binding.ReaderQuotas.MaxStringContentLength = 2147483647;
binding.ReaderQuotas.MaxArrayLength = 2147483647;
binding.ReaderQuotas.MaxDepth = 2147483647;
binding.ReaderQuotas.MaxBytesPerRead = 2147483647;
var address = new EndpointAddress("http://mylocalservice..");
ChannelFactory<IMyContract> factory = new ChannelFactory<IMyContract>(binding, address);
foreach (OperationDescription op in factory.Endpoint.Contract.Operations)
{
DataContractSerializerOperationBehavior dataContractBehavior =
op.Behaviors.Find<DataContractSerializerOperationBehavior>()
as DataContractSerializerOperationBehavior;
if (dataContractBehavior != null)
{
dataContractBehavior.MaxItemsInObjectGraph = 2147483646;
}
}
public IMyContract MyClientObject = factory.CreateChannel();
You can set the MaxReceivedMessageSize property on the service via the service's config file.
Setting the client's MaxReceivedMessageSize only affects messages received by the client; it has no effect on messages received by the service. Correspondingly, to allow the service to receive large messages, you need to set the service's config file.
Sample Service Config
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="MyBinding" maxReceivedMessageSize="2147483647" />
</wsHttpBinding>
</bindings>
<services>
<service name="MyService">
<endpoint address="http://myservice" binding="wsHttpBinding"
bindingConfiguration="MyBinding" contract="IMyServiceContract" />
</service>
</services>
</system.serviceModel>
The above is a very stripped down config file, but shows the relevant parts. The important part is that you define the binding and give it a name, and set any values explicitly that are different from the defaults, and use that name in the bindingConfiguration attribute on the endpoint element.
My problem was with the wcf test client. For some reason, it wouldn't generate a client config with the increased maxReceivedMessageSize. My fix was to right click "Config file" -> "Edit with SvcConfigEditor" -> bindings -> maxReceivedMessageSize.
This issue can be resolved by adding the below additional binding node to the binding section of config file.
<basicHttpBinding>
<binding maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>

WCF service The maximum array length quota (16384) has been exceeded

I have a wsf service and a client application. While trying to communicate the client and the service I've gotten the following message:
"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:blob. The InnerException message was 'There was an error deserializing the object of type FileBlob. 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. Line 1, position 25931.'. Please see InnerException for more details."
I have the customBinding element and it doesn't allow me to insert "readerQuotas" section. In both the client and service configs I have the following binding element:
<customBinding>
<binding name="LicenseServiceBinding"
closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00">
<security authenticationMode="UserNameOverTransport">
<localClientSettings maxClockSkew="00:07:00" />
<localServiceSettings maxClockSkew="00:07:00" />
</security>
<windowsStreamSecurity />
<httpsTransport maxReceivedMessageSize="2147483646"/>
</binding>
</customBinding>
Thanks in advance for any help:)
Actually, I've solved the problem by adding readerQuotas within textMessageEncoding section.
Thanks for the help.
<textMessageEncoding messageVersion="Soap11">
<readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="5242880"/>
</textMessageEncoding>
You should be able to add a <readerQuotas> element inside the <binding> element:
<customBinding>
<binding name="LicenseServiceBinding"
closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00">
<security authenticationMode="UserNameOverTransport">
<localClientSettings maxClockSkew="00:07:00" />
<localServiceSettings maxClockSkew="00:07:00" />
</security>
<readerQuotas maxArrayLength="32768" />
<windowsStreamSecurity />
<httpsTransport maxReceivedMessageSize="2147483646"/>
</binding>
</customBinding>
You mentioned that it "doesn't allow me to insert". What error message do you get?

configure console app to receive more than 65536 from wcf

Error Message:
The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
svc.map
<?xml version="1.0" encoding="utf-8"?>
<ServiceReference>
<ProxyGenerationParameters
ServiceReferenceUri="http://d3w9501/SimpleWCF/SimpleWCF.svc"
Name="svc"
NotifyPropertyChange="False"
UseObservableCollection="False">
</ProxyGenerationParameters>
<EndPoints>
<EndPoint
Address="http://d3w9501.americas.hpqcorp.net/SimpleWCF/SimpleWCF.svc"
BindingConfiguration="BasicHttpBinding_ISimpleWCF"
Contract="TestSimpleWCF.svc.ISimpleWCF"
>
</EndPoint>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISimpleWCF" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
</EndPoints>
</ServiceReference>
you need to set MaxReceivedMessageSize in app.config to higher value.
Like here :
alt text http://geekswithblogs.net/images/geekswithblogs_net/niemguy/7378/o_02%20-%20Properties%20BasicHttpBinding.jpg