.Net项目中需要调用一个只允许POST方式的WebService.
我在"添加Web引用"的窗口的地址中输入WebService的地址,返回404(未找到)的错误信息.服务器上的日志显示采用了GET方式.我不知道怎么改用POST方式来请用服务.
另外,我从网上下载了一个动态调用WebService的类,并调用其中的QuerySoapWebService方法,其中明确指定的POST方式,但还是返回同样的错误信息.
private static XmlDocument QuerySoapWebService(String url, String methodName, Hashtable Pars, string XmlNs,string cerPath)
{
_xmlNamespaces[url] = XmlNs;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "POST";
request.ContentType = "text/xml; charset=utf-8";
request.Headers.Add("SOAPAction", "\"" + XmlNs + (XmlNs.EndsWith("/") ? "" : "/") + methodName + "\"");
SetWebRequest(request, cerPath);
byte[] data = EncodeParsToSoap(Pars, XmlNs, methodName);
WriteRequestData(request, data);
XmlDocument doc = new XmlDocument(), doc2 = new XmlDocument();
doc = ReadXmlResponse(request.GetResponse()); //这里返回错误信息了.
XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
mgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
String RetXml = doc.SelectSingleNode("//soap:Body/*/*", mgr).InnerXml;
doc2.LoadXml(" <root>" + RetXml + " </root>");
AddDelaration(doc2);
return doc2;
}
请帮我分析分析,谢谢啦.
404错误是未找到对应的页面或服务,你直接在IE里输入地址访问呢?
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL + "/" + MethodName);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
SetWebRequest(request);
byte[] data = EncodePars(Pars);
WriteRequestData(request , data);
return ReadXmlResponse(request.GetResponse());