首页 新闻 搜索 专区 学院

webservice一直操作超时,url地址能用浏览器打开

0
[已解决问题] 解决于 2017-07-04 09:00

public static string SoapV12WebService(string URL, string MethodName, Hashtable Pars, string XmlNs)
        {
            ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
            //System.GC.Collect();
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
            //System.Net.ServicePointManager.DefaultConnectionLimit = 50;
            request.Method = "POST";
            request.ContentType = "application/soap+xml; charset=utf-8";
            //request.ContentType = "text/xml; charset=utf-8";
           
            // 凭证
            request.Credentials = CredentialCache.DefaultCredentials;
            //request.Credentials = new NetworkCredential("administrator","hiip123");
            //超时时间
            request.Timeout = 10000;
            //request.ReadWriteTimeout = 30 * 1000;
            byte[] data = HashtableToSoap12(Pars, XmlNs, MethodName);
            request.ContentLength = data.Length;
            Stream writer = request.GetRequestStream();
            writer.Write(data, 0, data.Length);
            writer.Close();
            var response =request.GetResponse();//----在这个位置一直操作超时。
            XmlDocument doc = new XmlDocument();
            StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string retXml = sr.ReadToEnd();
            //response.Close();
            sr.Close();
            doc.LoadXml(retXml);
            XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
            mgr.AddNamespace("soap12", "http://www.w3.org/2003/05/soap-envelope");
            string xmlStr = doc.SelectSingleNode("//soap12:Body/*/*", mgr).InnerXml;
            return xmlStr;
        }

yjcd的主页 yjcd | 初学一级 | 园豆:119
提问于:2017-06-27 10:15
< >
分享
最佳答案
0

抓包看请求报文

奖励园豆:5
吴瑞祥 | 高人七级 |园豆:28851 | 2017-06-27 10:43
其他回答(2)
0

f分析下浏览器动作和你这里模拟请求的动作差别,是不是差了参数header或者 认证之类的

hahanonym | 园豆:1460 (小虾三级) | 2017-06-27 11:53
0

超时的话要么timeout太小,还没执行完成,要么服务端阻塞。手动测试是不是可以,抓包看看。直接看你代码看不出什么。或者去掉  request.ContentLength = data.Length;这个试试。如果你request.ContentLength 设置大于实际数据包大小,也会一直阻塞到超时

我要挣钱 | 园豆:202 (菜鸟二级) | 2017-06-27 13:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册