I have a requirement where I need to send multiple parallel calls to different web services hosted on different servers. I have to read a configuration file to know how many times the call has to be made. Let say there are 4 servers and on each server a web service is hosted. The configured value is 4 then I have to make 4 calls to each service in parallel. Total calls would be 16. Here is the code which I have done:
string XmlFile = ConfigurationManager.AppSettings["XMLFile"].ToString();
int num = Convert.ToInt16(ConfigurationManager.AppSettings["NumberOfCalls"]);
Service service1 = new InfoMsg.Manager.Service();
Service service2 = new InfoMsg.Manager.Service();
Service service3 = new InfoMsg.Manager.Service();
Service service4 = new InfoMsg.Manager.Service();
string xmlString = System.IO.File.ReadAllText(XmlFile);
if (!string.IsNullOrEmpty(xmlString))
{
Parallel.For(0, num, i =>
Parallel.Invoke(() => service1.CheckInXML(xmlString),
() => service2.CheckInXML(xmlString),
() => service3.CheckInXML(xmlString),
() => service4.CheckInXML(xmlString))
);
}
I am actually making between 14 and 16 calls so something is wrong. Is it a correct way to do this?