Request entity too large error(413) in WCF - c#

I am facing 413 error in WCF service even if maxReceivedMessageSize is set to max i.e. 2147483647 and actual message size is less than 50kb.
This issue appears only when there is some ideal time between two request.
The exact scenario is as below:
1. Send 1000 messages each of them is around 38 kb. STATUS: PASS
2. Wait for sometime(Minimum 3 mins)
3. Send 1 message. STATUS: FAIL. (413 error)
I am using ws2007FederationHttpBinding. Web.config tag is as below:
<ws2007FederationHttpBinding>
<binding name="federationHttpBinding" openTimeout="00:04:00" closeTimeout="00:04:00" receiveTimeout="00:04:00" sendTimeout="00:40:00" maxReceivedMessageSize="2147483647">
<!-- <readerQuotas maxArrayLength="2147483647" maxDepth="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" /> -->
<security mode="TransportWithMessageCredential">
<message establishSecurityContext="false">
</message>
</security>
</binding>
</ws2007FederationHttpBinding>
Client side binding tag is as below:
<ws2007FederationHttpBinding>
<binding name="AuthorizationBinding" openTimeout="00:04:00" closeTimeout="00:04:00" receiveTimeout="00:04:00" sendTimeout="00:40:00" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxDepth="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
<security mode="TransportWithMessageCredential">
<message establishSecurityContext="false"/>
</security>
</binding>
</ws2007FederationHttpBinding>

I think you could solve this problem by removing the name attribute from the binding tag, A similar problem could be found here
WCF service maxReceivedMessageSize basicHttpBinding issue

You also have to set maxBufferSize
<binding name="federationHttpBinding"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647">

Related

WCF change timeout in runtime (serverside)

Hello I have one question about the wcf timeout.
I set the default timeout value 00:10:00 minutes.
but some service need more than 10:00 minutes. so I need to change timeout in server side programmatically.
I tried to change it but I can not find the way. Is there have any solution for this?
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="TCPBinding" portSharingEnabled="true" receiveTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" closeTimeout="00:10:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None"/>
<reliableSession enabled="true" inactivityTimeout="00:10:00"/>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
Ver2
I tried to check timeout with below code but still doesn't change.
OperationContext.Current.Channel.OperationTimeout

How to read an XML binding from Configuration into Controller in MVC

On a website i am maintaining dependant on customer needs, SSL is either turned on, or off.
I have the following binding set up in the applications Web.Config
<bindings>
<basicHttpBinding>
<binding name="TransferService" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed">
<readerQuotas maxDepth="2147483647" 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>
I would like to extract the binding's information and use it inside the websites application start event, but more specifically i would like to find out the security mode that is currently being used.
With this, i will be able to redirect the website to use HTTPS is the security mode="Transport" and not redirect if the website uses security mode="None"
So, how would i go about getting this binding into a controller?
I have tried the standard
IDictionary sampleTable = ictionary)ConfigurationManager.GetSection("bindings");
as well as something along the lines of
string securitsetting = ConfigurationManager.AppSettings[security]
but as i can obviously see, it is not the correct way to go about it!

WCF Service Content Type Issue

I have a wcf web servis. It works properly on our iis application server. Now I need to move this application into another server. Without changing anything, it doesn't work new server. The problem is service response type turned text\html. When I have tried on soap ui at header tab:
Content-Type text/html; charset=UTF-8
When I tried in a simple console application I have got following error:
The content type text/html; charset=UTF-8 of the response message does
not match the content type of the binding (text/xml; charset=utf-8)
What am I doing wrong?
EDIT: I just realized that It work with this binding settings:
<bindings>
<basicHttpBinding>
<binding name="Binding1" hostNameComparisonMode="StrongWildcard" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00" maxReceivedMessageSize="2147483647" maxBufferPoolSize="52428800" messageEncoding="Text" textEncoding="utf-8" bypassProxyOnLocal="false" useDefaultWebProxy="true">
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" />
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
When I change security mode to "None" (that I need) content type is become text\html

Why is there a long delay between WCF TransportReceive and ServiceLevelReceiveReply?

I have two environments running the same WCF web service but one of them seems to have a 3-5 minute delay returning the XML data. The slow down seems to occur in relation to the size of the data being returned. The web service just retrieves an XML string from a database so the processing time is constant.
The endpoint bindings are the same for both but I'm wondering what else would cause a delay.
I ran a trace and it shows that the TransportReceive happens at the same time on both environments, but on the delayed environment the ServiceLevelReceiveReply occurs after 3-5 minutes.
Any idea what could cause this? I'm happy to provide as much data as possible.
Here are the two bindings that are used. MyPolicySoap is used for getting the XML.
<basicHttpBinding>
<binding name="MyPolicySoap" closeTimeout="00:11:00" openTimeout="00:11:00" receiveTimeout="00:10:00" sendTimeout="00:11:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="5000000" maxBufferPoolSize="524288" maxReceivedMessageSize="5000000" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="5000000" maxArrayLength="16384" maxBytesPerRead="5000000" maxNameTableCharCount="16384"/>
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="MyConfig" maxReceivedMessageSize="2147483647">
<readerQuotas maxStringContentLength="2147483647"/>
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""><!--<extendedProtectionPolicy policyEnforcement="Never" />--></transport>
<message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true"/>
</security>
</binding>
</wshttpbinding>

Too long string for WCF

I'm trying to send a long string by WCF, around 64k chars long. When sending a long string, the I get the HTTP error 400. But when I send shorter string, everything works fine.
Here is the WCF interface and app.config that I use.
My message contract:
[MessageContract]
public class MessageClass
{
[MessageHeader(MustUnderstand = true)]
public string id;
[MessageBodyMember(Order=1)]
public string realMessage; // Long string
}
I have tried to change the app.config settings by rising the values:
<bindings>
<basicHttpBinding>
<binding
name="ws"
transferMode="Streamed"
messageEncoding="Mtom"
maxReceivedMessageSize="10067108864">
<readerQuotas
maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
Is there any other value that I should change?
You also need to set the "maxBufferSize" and "maxBufferPoolSize" on your binding:
<bindings>
<basicHttpBinding>
<binding
name="ws"
transferMode="Streamed"
messageEncoding="Mtom"
maxReceivedMessageSize="10067108864"
maxBufferSize="500000" maxBufferPoolSize="500000">
<readerQuotas
maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
Those also default to 64K in WCF's standard bindings. However, since you're using the "transferMode=Streamed", this really shouldn't be an issue - maybe there's something else going on. How about also increasing the sendTimeout setting? Maybe your service is just taking a tad too long to respond.
Marc
See the maxReceivedMessageSize attribute of the basicHttpBinding # http://msdn.microsoft.com/en-us/library/ms731361.aspx. Coindicentally, the default is 65,536 KB.

Categories