加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

call WebService show operation Time out exception

发布时间:2020-12-17 02:48:53 所属栏目:安全 来源:网络整理
导读:下面的代码将在一个线程中执行. 现在问题是当调用本机的webservice时,不会出现错误,但调用其它机器上的webservice时有时出现"操作超时"错误.,而且每调用成功2次后必定会出现该错误4次,好像是1:2的频率出现. ? ?public override bool Execute() ??????? { ???

下面的代码将在一个线程中执行. 现在问题是当调用本机的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;
??????????? }

??????? }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读