首页 新闻 会员 周边 捐助

.net中如何采用POST方式调用WebService?

0
悬赏园豆:10 [已关闭问题]

.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方式就可以啦.我不明白如何改.
Lucker的主页 Lucker | 初学一级 | 园豆:53
提问于:2010-02-24 11:31
< >
分享
其他回答(1)
0

404错误是未找到对应的页面或服务,你直接在IE里输入地址访问呢?

查尔斯 | 园豆:3832 (老鸟四级) | 2010-02-24 12:58
直接在IE里输入地址访问,早就试过了,一样是404错误.对方回复的邮件说:IE地址栏访问的方式就是采用的GET方式,所有不会被服务接受.
支持(0) 反对(0) Lucker | 园豆:53 (初学一级) | 2010-02-25 09:40
0

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());

persialee | 园豆:3217 (老鸟四级) | 2010-02-27 15:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册