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;
}
抓包看请求报文
f分析下浏览器动作和你这里模拟请求的动作差别,是不是差了参数header或者 认证之类的
超时的话要么timeout太小,还没执行完成,要么服务端阻塞。手动测试是不是可以,抓包看看。直接看你代码看不出什么。或者去掉 request.ContentLength = data.Length;这个试试。如果你request.ContentLength 设置大于实际数据包大小,也会一直阻塞到超时