WCF Hanging and slowing down after 10 Service requests



Quick post, for my own sanity. If you every find that your Service Requests via WCF are working fine, but after a seemingly short time they fail.

Often you'll get an TimeOutException

The operation has timed out
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The operation has timed out

Source Error:

With a stack trace like this:

[WebException: The operation has timed out]
   System.Net.HttpWebRequest.GetResponse() +1126
   System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +81

[TimeoutException: The HTTP request to 'http://localhost:85/CarService.svc' has exceeded the allotted timeout of 00:00:09.9990000. The time allotted to this operation may have been a portion of a longer timeout.]
   System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason) +6679397
   System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +15223563
   System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) +415

If you've got a WCF Service client that inherits from ClientBase like so

public class CarServiceClient : ClientBase,ICarService
    {
        public CarServiceClient()
            : base("CarService", new EndpointAddress("http://localhost:85/CarService.svc"))
        {   
            
        }
        public IList BrowseMakes()
        {
            return Channel.BrowseMakes();
        }

        public IList BrowseModels()
        {
            return Channel.BrowseModels();
        }

        public IList BrowseCarsByMake(MakeDto makeDto)
        {
            return Channel.BrowseCarsByMake(makeDto);
        }
}

when you construct the client, to call your service as shown below Check you've closed the Service client.

public JsonResult GetModelsForMake(MakeDto makeDto)
        {
            var serviceClient = new CarServiceClient();
            var models = serviceClient.BrowseModelsByMake(makeDto);
            serviceClient.Close(); //IMPORTANT DONT FORGET TO CLOSE IT

            return Json(models);
        }

Another waste of 2+ hours, hoping it saves someone else's time.


WCF - The remote server returned an unexpected response: (400) Bad Request. Service - When Uploading Files



Ok this is the 2nd time in the last month this has bitten me. Typically I previously solved it at work and just can't remember how so have been left for the past hour banging my head against the keyboard. I've also had the fabled MaxReceivedMessageSize in relation to this.

Download Sample WCF Service with FileUpload (1.15 mb)

But It's solved and it was SO simple it hurts me. Firstly we have a simple solution consisting of 2 projects.

  1. WCF Service application
  2. Console Application

App.Config

So we want to upload the file called Cake.jpg from the FileUpload.App to the FileUpload.Services project. It should be so simple shouldn't it.

Please not we have a app.config in the console applications project. This file should contain the following: Syntax highlighter didn't work so here's the file: app.config.xml (1.85 kb)

Web.Config

Your Web.config should look like this: Web.config.xml (9.94 kb)

References


Search

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2014