下面的代码将在一个线程中执行. 现在问题是当调用本机的webservice时,不会出现错误,但调用其它机器上的webservice时有时出现"操作超时"错误.,而且每调用成功2次后必定会出现该错误4次,好像是1:2的频率出现.
?
?public override bool Execute()
??????? {
??????????? try
??????????? {
??????????????? HttpWebRequest req = (HttpWebRequest)WebRequest.Create(m;
??????????????? req.ContentType = "text/xml";
??????????????? req.Accept = "text/xml";
??????????????? req.Method = "POST";
??????????????? StringBuilder strBld = new StringBuilder(); //"<?xml version=/"1.0/" encoding=/"utf-8/"?>"
??????????????? strBld.Append("<soap12:Envelope xmlns:xsi=/"http://www.w3.org/2001/XMLSchema-instance/" xmlns:xsd=/"http://www.w3.org/2001/XMLSchema/" xmlns:soap12=/"http://www.w3.org/2003/05/soap-envelope/">");
??????????????? strBld.Append("<soap12:Body>");
??????????????? strBld.AppendFormat("<HelloWorld xmlns=http://www.abc.com/>");
??????????????? strBld.Append("</soap12:Body>");
??????????????? strBld.Append("</soap12:Envelope>");
??????????????? Stream stream = req.GetRequestStream(); //这里有时出现"操作超时"
??????????????? stream.Write(System.Text.ASCIIEncoding.ASCII.GetBytes(strBld.ToString()),strBld.Length);
??????????????? stream.Close();
??????????????? HttpWebResponse response = (HttpWebResponse)req.GetResponse();
??????????????? if (response.StatusCode == HttpStatusCode.OK)
??????????????? {
??????????????????? return true;
??????????????? }
??????????????? else
??????????????? {
??????????????????? this.LastError = "服务器段错误代码:" + response.StatusCode.ToString();
??????????????????? return false;
??????????????? }
??????????? }
??????????? catch (Exception e)
??????????? {
??????????????? this.LastError = "执行出错:" + e.Message;
??????????????? return false;
??????????? }
??????? }