Link to home
Start Free TrialLog in
Avatar of SWS001
SWS001

asked on

How do I fix this Connection Socket problem in WCF?

Hi all,

We have an ASP.NET site hosted on IIS6, talking to a WCF service hosted as a Windows Service. This is over a nettcpbinding.

This generally works very nicely, but I noticed today if a few of us attempt connections, or I raise many page requests myself in quick succession it all stops and begins to time out. Once everything has finished timing out it's good to go again.

I have set

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)]

above my IWcfService interface to avoid concurrency problems, but it's made no difference.

I have zipped and attached our WCF trace log where you can see it runs smoothly, then dies, and repeats this. I had to rename the file from WcfTrace.svclog to WcfTrace.svclog.txt to upload it so please change the extension back.

Many thanks
Avatar of williamcampbell
williamcampbell
Flag of United States of America image

What sort of data is the service accessing ... there may be issues where multiple requests to the data are causing lockups.

Do you have Multiple Threads running in the Code? You may have a Deadlock.

Avatar of SWS001
SWS001

ASKER

I haven't coded anything to be multi threaded per se, I was under the impression each session from IIS would get it's own instance.

It's accessing a sql 2005 database, and returning from that. I'll put a profiler on the database to have a look, but it's the same database we used to use prior to going wcf and haven't had that issue before.

Thanks
Avatar of SWS001

ASKER

I have this at the top of my wcf service class

    [DataContract(Namespace = "http://schemas.mycompany.com/ORS2")]
    [KnownType(typeof(System.Collections.Hashtable))]
    [KnownType(typeof(Request))]
    [KnownType(typeof(SubRequest))]
    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)]
    public class WcfService : IWcfService
    {
Avatar of SWS001

ASKER

I think it might be because I'm not closing my WcfServiceClient in any of my aspx pages...
Avatar of SWS001

ASKER

Another thing I've done which appears to have helped
In my app.config under ServiceBehaviours

<serviceThrottling maxConcurrentCalls="16"
maxConcurrentInstances="2147483647"
maxConcurrentSessions="64"/>
I think it might be because I'm not closing my WcfServiceClient in any of my aspx pages..

Yeah you can run out of resources this way .. wrap it in a using block
Avatar of SWS001

ASKER

I see that a using statement with wcf service client can cause issues masking exceptions.

http://msdn.microsoft.com/en-us/library/aa355056.aspx
http://www.iserviceoriented.com/blog/post/Indisposable+-+WCF+Gotcha+1.aspx
http://blog.davidbarrett.net/archive/2007/11.aspx

Will I be ok for now just being careful where I close clients? I could do something like





 public partial class WcfServiceClient : IDisposable
{

    void IDisposable.Dispose() {

        if (this.State == CommunicationState.Faulted) {
            this.Abort();
        } else {
            this.Close();
        }

    }

}



and then I just start and stop my methods with a using statement right?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of williamcampbell
williamcampbell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial