Call web service methods in specific order
I have two web service calls, Method1() and Method2().
If a boolean variable is set to true, Method1() should be called first, then Method2(). If the boolean variable is set to false, only Method2() should be called.
When I look at the timestamps of the xml files, I can see that request/response of Method1() have a newer timestamp than files for Method2(), which suggest that Method2 is called before Method1.
Is there a way to wait for Method1() to complete before Method2() gets called?
var client = new WebServiceClient();
bool myBoolean = true;
if (myBoolean)
{
XmlHandler.ToXML(method1Request, "C:/Temp/method1RQ.xml");
var method1Response = client.Method1(method1Request);
XmlHandler.ToXML(method1Response, "C:/Temp/method1RS.xml");
}
XmlHandler.ToXML(method2Request, "C:/Temp/method2RQ.xml");
var method2Response = client.Method2(method2Request);
XmlHandler.ToXML(method2Response, "C:/Temp/method2RS.xml");
client.Close();
Code in XmlHandler:
public static void ToXML(object obj, string savePath)
{
if (obj != null)
{
try
{
if (File.Exists(savePath))
{
File.Delete(savePath);
}
XmlSerializer serializer = new XmlSerializer(obj.GetType());
using (XmlTextWriter xmlWriter = new XmlTextWriter(savePath, System.Text.Encoding.UTF8))
{
serializer.Serialize(xmlWriter, obj);
xmlWriter.Close();
}
}
catch (Exception exc)
{
}
}
}
Is there a way to wait for Method1() to complete before Method2() gets called?
That is the default behaviour with synchronous calls, which you are using.
My best guess is that you have fired off two service clients concurrently.
Look at the server logs to see when the calls came in.
It could also be that you are looking at a timestamps on local files that were flushed as a result of finalization at the end of the program, so the timing / order is undefined.
I'm not familiar with XmlHandler, but whatever XmlHandler is doing internally, make sure to Close, Flush and/or Dispose the StreamWriters.
链接地址: http://www.djcxy.com/p/60432.html上一篇: 如何通过IIS日志查找服务器处理时间?
下一篇: 按特定顺序调用Web服务方法