在循环中调用 WCF 时没有响应
我尝试使用循环的 WCF 服务在数据库中生成大量用户。 脚本和 Web 服务在本地运行 (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();
问题是,大约有 3300 个调用启动了 EndpointNotFoundException,并出现以下 innerException:“无法连接到远程服务器”。
我需要等待大约 20 秒才能继续该过程而不会出现错误(直到下一个 3300 次调用)。
是代码问题还是服务器限制?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在服务中创建一个新操作,将用户列表作为参数。然后,您可以使用列表调用它一次,而不是使用一个用户调用现有操作 20000 次。它将减少网络负载并简化交易的使用。
如果不可能,请激活 WCF 跟踪 并检查调用时会发生什么情况失败。
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.