Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I have a requirement,
I am doing some service validations. so i need to invoke two services at a same time both service call has to hit on the same time.
Can i use threading? If yes how?
Whats the best method to achieve my requirement

My code is as follows
C#
//First Part
string SOAPAction = "http://tempuri.org/Holdings/GetTopPositions";
                string ReqXML = (new WebServicesAutomationFramework.XMLMapper.DataToRequestXMLMapper(BaseTestClassProp.RequestMap[TestContext.DataRow["ReqMapName"].ToString()],
                    XDocument.Parse(BaseTestClassProp.DataInsertMap[TestContext.DataRow["ReqMapName"].ToString()].ToString()), TestContext)).MapToXML();                
                _iTestFactory.SourceServiceCall = new WebServicesAutomationFramework.Entities.ServiceCallEntity(ReqXML, SOAPAction, WebServicesAutomationFramework.Common.ConfigurationSettings.SourceUrl
                                 , WebServicesAutomationFramework.Common.ConfigurationSettings.RedirectUrl, true, "POST");               
                string GetTopPositionXML = _iTestFactory.SourceServiceCall.RespData.Response;

//Second part
                string SOAPAction2 = "http://tempuri.org/Holdings/GetRequestedData";
                string ReqXML2 = string.Format(doc.ToString(), TestContext.DataRow["SignOnRACFID"].ToString(), TestContext.DataRow["Office"].ToString(), TestContext.DataRow["Account"].ToString());
                _iTestFactory.SourceServiceCall = new WebServicesAutomationFramework.Entities.ServiceCallEntity(ReqXML2, SOAPAction2, WebServicesAutomationFramework.Common.ConfigurationSettings.SourceUrl
                                 , WebServicesAutomationFramework.Common.ConfigurationSettings.RedirectUrl, true, "POST");
                string GetRequestedDataXML = _iTestFactory.SourceServiceCall.RespData.Response;

//Both Service response i need to pass to another method
                DefectFix.ServiceValidation(ReqXML, GetTopPositionXML, GetRequestedDataXML, TestContext.DataRow["TestCaseName"].ToString(), "GetTopPositions", sb);
Posted
Comments
[no name] 3-Aug-15 11:06am    
Given that Windows uses pre-emptive multitasking, what would be your definition of the "same time" since you will likely never get function calls to occur at the exact same time.
Sergey Alexandrovich Kryukov 3-Aug-15 11:24am    
"Threading" does not mean "at the same time", it means "in parallel". Can you spot the difference?
You can use multithreading through starting to read on this topic.
—SA

1 solution

You can't guarantee execution order, or even similar execution times in a pre-emptive multitasking system, since the system is at liberty to suspend and activate threads at will, and the availability of free cores controls how many "things happen at the same time".

And to add to that, the internet itself is non-deterministic: messages can take different routes through and thus take different times. And when they get to the other end, there is absolutely no guarantee when they will be serviced - again it will depend on the availability of spare processing power and the load on the equipment at the other end.

So basically, the answer is "no". You cannot guarantee simultaneous execution of your two service requests.
 
Share this answer
 
Comments
jinesh sam 5-Aug-15 2:31am    
Thanks..Its very informative
OriginalGriff 5-Aug-15 2:49am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900