WCF not responding when calling it in an loop

306 views Asked by At

I try to generate a lot of User in my DB using a WCF service using a loop. The script and the web service are running locally (Cassini).

                FormWCFClient formClient = new srForm.FormWCFClient();
                User user;
                int nbUser = 20000;
                for (int i = 0; i < nbUser; ++i)
                {
                    user = new User();
                    user.Email = String.Format("{0}@example.com", i.ToString());

                    formClient.AddUser(user); // Add the user in DB
                }

                formClient.Close();

The problem is that around 3300 calls an EndpointNotFoundException is launched with the following innerException : "Unable to connect to the remote server".
I need to wait around 20 seconds in order to be able to continue the process without error (until the next range of 3300 calls).

Is it a code problem or a server limitation ?

1

There are 1 answers

1
Johann Blais On BEST ANSWER

You could create a new operation in your service that takes a list of users as a parameter. Then you would call it once with the list instead of calling the existing operation 20000 times with one user. It would reduce the load on the network and ease the use of transactions.

If not possible, then activate WCF tracing and check what happens when the call fails.