The request channel timed out while waiting for a reply - c#

I have a small application that uses WCF to communicate with a webserver. This program is used by some 200 clients, and each client is sending in about 5-20 requests/min.
Looking at the error logs I often get:
The request channel timed out while waiting for a reply after
00:00:59.9989999
The requests are made as follows:
ClientService Client = new ClientService();
Client.Open();
Client.updateOnline(userID);
Client.Close();
This is the app.config
<configuration>
<configSections>
</configSections>
<startup><supportedRuntime version="v2.0.50727"/></startup><system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IClientService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="PATH TO SERVICE"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IClientService"
contract="IClientService" name="WSHttpBinding_IClientService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
Of the "many calls" each day about 200-800 fail. And about n-1 are ok. I am very confused what the issue can be. Looking at the server stats, it's hardly building up a sweat - each request takes <2 sec to process. The data it's sending consists of "int" or "very small strings" - so, its not due to size, if it were - there should be a consistent failure..
Suggestions?

Try adding the timeout values to both the service AND the client:
<binding name="BasicHttpBinding_SomeName" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00"
sendTimeout="00:10:00" maxBufferPoolSize="2147483647"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">

It seems that your requests are queuing up on server before being handled and then starts to time out. You can try couple of things here to see exactly whats going on
1) Try throttling in your WCF services e.g: Try increasing your concurrent sessions. Take a look
WCF Throttling
2) Try using PerCall rather than Using Sessions here to make sure that no session remains there.
Here is what you can do on your interface to remove session
[ServiceContract(Namespace="YOUR NAMESPACE", SessionMode=SessionMode.NotAllowed)]
and your contract classes implementing those interface
ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
AND .... You should enable tracing to see exactly whats going on .

Check this performance counter - ASP.NET Requests Queued.
One web application can host many web pages and services. IIS processes only 12 concurrent requests per CPU core by default.
This means that even if your service is fast but other pages/services are slow your request has to wait in queue before they are executed.
ASP.NET Requests Queued should be zero or close to zero.
See Performance Counters for ASP.NET on MSDN.

Related

WCF Memory Increases dramatically

I am using WCF service. The problem I have is its starts using double memory.
I am using HTTPS binding
<wsHttpBinding>
<binding name="secureHttpBinding" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="Transport" >
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
<endpoint address="https://localhost/test.svc"
binding="wsHttpBinding"
bindingConfiguration="secureHttpBinding"
contract="IWcfContract"
name="SecureBasicHttpBinding_WcfContract">
Here is the code I am using to upload
using (Stream fileStream = File.OpenRead(logsZipFullPath))
{
// Call web server
UploadFileResponse response = _webServiceHelper.UploadFile(fileStream, currentDate, ".zip", string.Empty);
fileStream.Close();
}
Here is my model
[MessageContract]
public class UploadFileRequest : IDisposable
{
[MessageBodyMember(Order = 1)]
public Stream FileByteStream;
[MessageHeader(MustUnderstand = true)]
public string FileDescription;
}
My zip file is of 80MB.
The problem I have is at the start of the service its using 26mb which is quite fine. At the first call it uses 136MB after call completes it goes down to 26mb. which is also fine. after the second call to upload it starts using 346MB
which again gets down to 26mb after service call. My question is why it is using 346MB when the file is of only 80MB? My GC and disponse has been called correctly. But, is this normal behaviour or I am missing anything?
finally found a work around for this. According to this post
wsHttpBinding is the full-blown binding, which supports a ton of WS-*
features and standards - it has lots more security features, you can
use sessionful connections, you can use reliable messaging, you can
use transactional control - just a lot more stuff, but wsHttpBinding
is also a lot *heavier" and adds a lot of overhead to your messages as
they travel across the network
I think this is the main reason why the memory usage is high. Our requirement was to use the HTTPS certificate and we are able to use this with basicHttpBinding. SO, I changed my settings like this
<basicHttpBinding>
<binding name="BasicHttpBinding_WcfContract" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="Transport"> <-- this is the main change
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
Note: I changed security mode none to transport to support https.
Now, everything works without the issue.
Two possible things which causes memory issues.
wsHttpBinding overheads
Stream mode is not supported in wsHttpBinding

Sharing web service methods

I am writing web service client in .Net c# which consumes stage and production web services.Functionality of web methods is same in both stage and production.
Client wants capability of using web methods from both production and stage web services for some data validation. I can do this generating two separate proxy classes also two
separate code bases. Is there a better way so that I can eliminate redundant code by doing something like below
if (clintRequest=="production")
produtionTypeSoapClient client= new produtionTypeSoapClient()
else
stageSoapClient client= new stagetypeSoapClient()
//Instantiate object. Now call web methods
client.authenticate
client.getUsers
client.getCities
You should be able to get away with just one client. If the contract is the same, you can specify the endpoint configuration and the remote address programmatically.
Let us say you have something like this:
1) Staging - http://staging/Remote.svc
2) Production - http://production/Remote.svc
If you are using Visual Studio you should be able to generate a client from either endpoint.
You should, then, be able to do something like this:
C# Code:
OurServiceClient client;
if (clientRequest == "Staging")
client = new OurServiceClient("OurServiceClientImplPort", "http://staging/Remote.svc");
else
client = new OurServiceClient("OurServiceClientImplPort", "http://production/Remote.svc");
This should allow you to use one set of objects to pass around. The 'OurServiceClientImplPort' section above is referencing the config file for the endpoint:
Config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="OurServiceClientSoapBinding" openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="128" maxStringContentLength="9830400" maxArrayLength="9830400" maxBytesPerRead="40960" maxNameTableCharCount="32768"/>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" realm=""/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<!-- This can be either of the addresses, as you'll override it in code -->
<endpoint address="http://production/Remote.svc" binding="basicHttpBinding" bindingConfiguration="OurServiceClientSoapBinding" contract="OurServiceClient.OurServiceClient" name="OurServiceClientImplPort"/>
</client>
</system.serviceModel>

Send Large Data with WCF without Streaming

We are trying to build a web service that can send/receive large data files from kb~gb sizes.
I know that we should use streaming to preform that so is not going to crash the memory.
But problem is we don't want to change our design, or more like, now we are going to try to see what will happen when we transfers large file say just 150mb file in a byte[] buffered transfers mode with WCF. (I know is goign to buffer the whole file into memory... and crash/exception if we transfer gb size files...)
But even so, they want to see what happen, so I have my wsHttpBinding in WCF config:
<system.web>
<compilation debug="true"/>
<httpRuntime maxRequestLength="524288"/>
</system.web>
....
<wsHttpBinding>
<binding name="wsHttpBinding1" closeTimeout="00:10:00" openTimeout="00:10:00"
receiveTimeout="00:30:00" sendTimeout="00:30:00" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="52428800" maxReceivedMessageSize="65536000"
messageEncoding="Mtom" useDefaultWebProxy="true">
<security mode="None" />
</binding>
</wsHttpBinding>
Then my client app config:
<wsHttpBinding>
<binding name="WSHttpBinding_IPrintService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="52428800" maxReceivedMessageSize="65536000"
messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None"/>
</binding>
</wsHttpBinding>
When I transfers small data it works fine, but when I try to transfers 150mb file, it gives me exceptions:
InnerException = {"Unable to write data to the transport
connection: An operation on a socket could not be performed because
the system lacked sufficient buffer space or because a queue was
full."}
I tried to increase maxReceivedMessage and such, but it still having the same problem....
======
Edit: I tried to increase all possible value above to... 2147483647.... I can sent a 30mb file successfully..but still not 150mb.... And I also tried to use this CustomBinding:
<customBinding>
<binding name="LargeCustomBinding"
receiveTimeout="01:00:00"
openTimeout="01:00:00"
closeTimeout="01:00:00"
sendTimeout="01:00:00">
<binaryMessageEncoding
maxReadPoolSize="2147483647"
maxSessionSize="2147483647"
maxWritePoolSize="2147483647">
<readerQuotas
maxArrayLength="2147483647"
maxDepth="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"
maxStringContentLength="2147483647" />
</binaryMessageEncoding>
<httpTransport
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647"
maxBufferPoolSize="2147483647"/>
</binding>
</customBinding>
But I am still getting the same problem....
=========
Edit 2: I guess I should put concern on how I sending the data, maybe I was wrong, I have an Object MyData:
byte[] LargeData = File.ReadAllBytes(this.LargeDataPath.Text);
MyData.LargeData = new List<KeyValuePair<string, byte[]>>()
{
new KeyValuePair<string, byte[]>("DATA", LargeData)
};
myServiceClient.SendDataAsync( new SendDataRequest(MyData));
There should be no problem? All I did is just sending one big byte[] inside a list.....
You should be sending a smaller chunks of data with a separate send method calls.
Put the data you want to send into a byte array.
Then realize the logic on both ends, that will know how to handle sizes and just start sending the data in a smaller pieces, one by one. When you have sent an entire file, it will get concatenated into an array on a client and you will be able to do further processing.
Fix this first:
maxStringContentLength="8192"
maxArrayLength="16384"
And ensure you have
maxStringContentLength="2147483646"
maxArrayLength="2147483646"
On both client and server.
I was sending 30Mb over WCF without problems.
And check out this

Getting started with Paypal Adaptive Payments in C# SOAP

I'm trying to start with Adaptive Payments by Paypal using SOAP interface.
When adding service reference to https://svcs.sandbox.paypal.com/AdaptivePayments?WSDL the following warning is shown by Visual Studio:
Custom tool warning: Cannot import wsdl:binding
Detail: The WSDL binding named AdaptivePaymentsSOAP11Binding is not valid because no match for operation CancelPreapproval was found in the corresponding portType definition.
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://svcs.paypal.com/services']/wsdl:binding[#name='AdaptivePaymentsSOAP11Binding'] C:\cproj\daemon\Service References\PaypalSandboxApi\Reference.svcmap 1 1 daemon
Discarding this message, the reference added successfully.
In order to perform a transaction, I try to create the client:
var client = new PaypalSandboxApi.AdaptivePaymentsPortTypeClient()
This throws InvalidOperationException:
Could not find default endpoint element that references contract 'PaypalSandboxApi.AdaptivePaymentsPortType' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
Am I missing something?
Should I use missing AdaptivePaymentsSOAP11Binding and not AdaptivePaymentsPortTypeClient?
It looks like importing this WSDL doesn't generate the servicemodel config. I kludged one together like this (and updated the relevant classname to match yours, so you can copy/paste):
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="PaypalAdaptivePayBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="1048576" maxBufferPoolSize="1048576" maxReceivedMessageSize="1048576" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="65536" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://svcs.sandbox.paypal.com/AdaptivePayments"
binding="basicHttpBinding" bindingConfiguration="PaypalAdaptivePayBinding"
contract="PaypalSandboxApi.AdaptivePaymentsPortType"
name="PaypalAdaptivePay" />
</client>

WCF listenBacklog and maxConnections can't be set higher than 10. Why not?

My service works great under low load. But under high load I start to get connection errors.
I know about other settings but I am trying to change the listenBacklog parameter in particular for my TCP Buffered binding.
If I set listenBacklog="10" I am able to telnet into the port where my WCF service is running.
If I change listenBacklog to anything higher than 10 it will not let me telnet into my service when it is running.
No errors seem to be thrown.
What can I do?
I get the same problem when I change my maxConnections away from 10. All other properties of the binding I can set higher without a problem.
Here is what my binding looks like:
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IMyService" 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="524288"
maxBufferSize="1048576" maxConnections="10" maxReceivedMessageSize="1048576">
<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">
</transport>
<message clientCredentialType="Windows" />
</security>
</binding>
...
I really need to increase the values of maxConnections and listenBacklog
If you're running on a Win2000, XP, Vista or Win7 machine, then the OS is limiting you to 10 concurrent TCP connections. Try running on a Windows Server machine to confirm.
This is almost certainly a throttling issue. Try specifying non-default values for the service throttling behavior values. See this page for some guidance.
Try to remove all references to HTTP bindings and MEX.

Categories