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.
Related
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
I need to add this block to my binding in my web.config when there is a release compilation :
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
Here is the snippet of my web.config :
<bindings>
<basicHttpBinding>
<binding name="BasicBinding" closeTimeout="24.20:31:23.6470000" openTimeout="24.20:31:23.6470000" receiveTimeout="24.20:31:23.6470000" sendTimeout="24.20:31:23.6470000" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
And here is my transformation method web.release.config following this documentation :
<bindings>
<basicHttpBinding>
<binding>
<security mode="Transport" xdt:Transform="InsertAfter(/configuration/system.serviceModel/bindings/basicHttpBinding/binding)">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
I face the following erreur on compilation on VSTS :
[error]Sources\Foo.Interface\Web.Release.config(16,6): Error : No element in the source document matches '/configuration/bindings/basicHttpBinding'
Of course I tried with other similar values but facing all time the same issue.
Not clear about the error. But if you want to insert security node into your web.config's binding node, you could write the following code in your web.release.config
using xdt:Transform="Insert"
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicBinding" >
<security mode="Transport" xdt:Transform="Insert" >
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
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!
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">
I have a method like this:
var stringReader = new StringReader(ruleSetXmlDefinition);
var reader = XmlReader.Create(stringReader);
var serializer = new WorkflowMarkupSerializer();
return serializer.Deserialize(reader) as RuleSet;
When the ruleSetXmlDefinition is greater than 32768 characters long I get the following error:
Unexpected end of file while parsing Name has occurred. Line 1,
position 32768.
How can I change this so that it can handle strings of any length?
I suspect you can configure Wcf to accept bigger arrays, see also this answer:
Maximum array length quota
Something like
<netTcpBinding>
<binding name="NetTcpBinding_ImageResizerServiceContract" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
I have found the answer to this issue and unfortunately it was something really obvious...the string I was passing in was actually being truncated so the issue was actually that the xml was not well formed.