private void button2_Click(object sender, EventArgs e) { Hashtable ht = new Hashtable(); ht["schoolid"] = "58df1006-faec-4f98-a643-2b0bfce26427"; ht["pageindex"] = "1"; ht["pagesize"] = "909"; webBrowser1.DocumentText = WebSer_Post("GetStudentNotice", ht); } string url = "http://localhost:9992/CCDist2Srv.asmx"; public string WebSer_Get(string methodName, Hashtable htParms) { string queryURL = string.Format("{0}/{1}?{2}", url, methodName, ParmsToString(htParms)); HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(queryURL); StreamReader sr = new StreamReader(req.GetResponse().GetResponseStream(), Encoding.UTF8); string str = sr.ReadToEnd(); return str; } public string WebSer_Post(string methodName, Hashtable htParms) { string queryURL = string.Format("{0}/{1}", url, methodName); HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(queryURL); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.Timeout = 10000; string strpost = ParmsToString(htParms); byte[] bytParms = Encoding.UTF8.GetBytes(strpost); req.ContentLength = bytParms.Length; Stream sw = req.GetRequestStream(); sw.Write(bytParms, 0, bytParms.Length); sw.Close(); HttpWebResponse res; try { htParms.Clear(); res = (HttpWebResponse)req.GetResponse(); } catch (WebException ex) { res = (HttpWebResponse)ex.Response; } StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8); string str = sr.ReadToEnd(); return str; }
C#编写的webservice,某些特殊情况可能是返回值是void类型,实际的输出数据通过
Respose.Write();
Reponse.End();来输出.
这种情况获取的方法见如上代码.
分为Get和Post.
Soap获取的方法请参看这篇博客
http://www.cnblogs.com/eagle1986/archive/2012/09/03/2669699.html