WCF change timeout in runtime (serverside) - c#

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

Related

Add web.release.config value at compilation

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>

Request entity too large error(413) in WCF

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">

WCF webservice over basicHttpBinding with Streaming uses over 2 gigs of ram

I have an IIS hosted WCF webservice, it has two endpoints, one for wsHttpBinding, the other is for basicHttpBinding. I use basicHttpBinding so I can set the transferMode to "Streamed" so I can stream files. This service also is under SSL and needs a client certificate to connect to.
When I call the wsHttpBinding services and everything is fine. When I call the basicHttpBinding services to stream a file it will use all the free ram (the machine has 2.5 gigs) and then hits the page file and throws hard faults. All these hard faults and disk swapping causes the services to time out since it's taking longer than 60 seconds to return.
Below is the function that I am calling that is eating all the ram and timing out
[OperationBehavior]
public Stream GetOrderResults(string clientName, string userName, string password, string institutionId, Guid orderId, string fileName)
{
var fileStream = new System.IO.FileStream(#"\\iwebdev510\Relateprod\TDHub\Temp\TDTestClient\bob.xml", FileMode.Open);
return fileStream;
}
The configuration file for the client calling the webservice looks like this:
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<system.serviceModel>
<!-- REMOVE THE BEHAVIORS FOR DEV TESTING -->
<behaviors>
<endpointBehaviors>
<behavior name="ClientCertBehavior">
<clientCredentials>
<clientCertificate x509FindType="FindByThumbprint" findValue="8b08c6e6e356a345212e539979fbcaca337aae8a"/>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<!--Dev Endpoints With Certs-->
<endpoint address="https://<obfuscated>/secure/TDHubService.svc"
behaviorConfiguration="ClientCertBehavior"
binding="wsHttpBinding"
bindingConfiguration="wsTDHubServiceBindingTLS"
contract="MortgageCadence.External.TDHub.Protocols.Contracts.Services.ITDHubService" />
<endpoint address="https://<obfuscated>/secure/TDHubFileTransferService.svc"
behaviorConfiguration="ClientCertBehavior"
binding="basicHttpBinding"
bindingConfiguration="basicTDHubFileTransferServiceBindingTLS"
contract="MortgageCadence.External.TDHub.Protocols.Contracts.Services.ITDHubFileTransferService" />
</client>
<bindings>
<basicHttpBinding>
<binding name="basicTDHubFileTransferServiceBinding" maxReceivedMessageSize="2147483647"
transferMode="Streamed">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None" />
</binding>
<binding name="basicTDHubFileTransferServiceBindingTLS" maxReceivedMessageSize="2147483647"
transferMode="Streamed">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="wsTDHubServiceBinding" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None" />
</binding>
<binding name="wsTDHubServiceBindingTLS" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
I can provide a screen shot of the computers resource monitor being eaten by w3wp.exe, but I can't attach it ATM because my reputation is not high enough.
I have discovered that if I change the transfer mode from "Steamed" to "Buffered" in the binding it completely solves the memory issue, but this appears to be counter to what the documentation suggests. The documentation makes it sound like if you choose "buffered" it will load the entire file into memory before sending, but I've sent a 700 meg file and the memory didn't change in buffered mode.

(400) Bad Request when transferring large files

I have the same problem when trying to transfer files larger than 50kb the error message is "(400) Bad Request"
Can someone tell me where I'm wrong?
The following code below:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IFileTransfer" closeTimeout="00:10:00"
openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
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" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<client>
<endpoint address="http://localhost:57728/FileTransfer.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IFileTransfer" contract="WCFFileTransfer.IFileTransfer"
name="BasicHttpBinding_IFileTransfer" />
</client>
</system.serviceModel>
</configuration>
Make sure the web.config on the server has the following setting:
<system.web>
<httpRuntime maxRequestLength="2147483647" />
....
</system.web>

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