Kyle
Kyle

Reputation: 29

2 WCF Services and c# threading

I am trying to write code that imports a bunch of data as quickly and reliably as possible. Using threading I have been able to speed up the import code I wrote significantly on my local machine, but when I run it on our remote server it seems to have some WCF problems...

I have two WCF Service implementations: Service1 and Service2.

Basically this is the workflow:

Parallel.ForEach(objectData.Tables[0].Rows.Cast<DataRow>(), dataRow =>
{
...
    Service1.ImportObjectFirstPart(ObjectToEnter);
...
    Service2.ImportObjectSecondPart(ObjectToEnter);
}

Service1 call takes about 3 seconds, and service2 takes about 7 seconds both remotely and locally. However on my local machine, calls to service2 start after about 20 service1 calls. On the server, almost every service1 call finished before the first service2 call started. (Both services are implemented as PerCall).

The code to call the services uses 99% CPU as expected for awhile then slows to a crawl, then I have to exit it myself. Any idea what could be going wrong?

Thanks,

Upvotes: 2

Views: 417

Answers (1)

Ovais
Ovais

Reputation: 276

Have you tried

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]

you can read the details here

http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.concurrencymode.aspx

The default is single so you should expect the behavior you are getting is pretty justified.

Upvotes: 1

Related Questions