.net中如何采用POST方式调用WebService?
.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;
}
请帮我分析分析,谢谢啦.
问题补充:以下是服务方的技术人员用邮件发给我的服务器上的日志记录:
10.221.5.102 - - [24/Feb/2010:12:31:23 +0700] "POST /cpg2/CPGWSClientTest/LOTUS_ws_client.jsp HTTP/1.1" 200 13342
127.0.0.1 - - [24/Feb/2010:12:32:06 +0700] "POST /cpg/CPGWSOnline/services/OnlineTopupService HTTP/1.1" 200 1183
10.221.5.102 - - [24/Feb/2010:12:32:06 +0700] "POST /cpg2/CPGWSClientTest/LOTUS_ws_client.jsp HTTP/1.1" 200 13319
127.0.0.1 - - [24/Feb/2010:12:33:17 +0700] "POST /cpg/CPGWSOnline/services/OnlineTopupService HTTP/1.1" 200 1193
10.221.5.102 - - [24/Feb/2010:12:33:17 +0700] "POST /cpg2/CPGWSClientTest/LOTUS_ws_client.jsp HTTP/1.1" 200 13330
10.221.5.102 - - [24/Feb/2010:13:17:25 +0700] "GET /cpg/CPGWSOnline/services/OnlineTopupService?WSDL HTTP/1.1" 302 -
10.221.5.102 - - [24/Feb/2010:13:17:25 +0700] "GET /cpg/CPGWSOnline/services/OnlineTopupService/wsdl/OnlineTopupService.wsdl HTTP/1.1" 200 2639
10.221.5.102 - - [24/Feb/2010:13:17:25 +0700] "POST /cpg/CPGWSOnline/services/OnlineTopupService HTTP/1.1" 200 1197
10.221.5.102 - - [24/Feb/2010:13:17:27 +0700] "POST /cpg/CPGWSOnline/services/OnlineTopupService HTTP/1.1" 200 1189
127.0.0.1 - - [24/Feb/2010:13:49:08 +0700] "POST /cpg/CPGWSOnline/services/OnlineTopupService HTTP/1.1" 200 1181
10.221.5.102 - - [24/Feb/2010:13:49:08 +0700] "POST /cpg2/CPGWSClientTest/LOTUS_ws_client.jsp HTTP/1.1" 200 13311
中间有两行是GET方式的,他说改为POST方式就可以啦.我不明白如何改.
所有回答(1)文章来源:http://it503.com/detail.PHP
关键词:.net中如何采用POST方式调用WebService?,aspx
