asp.net 手工调用 WS(Get)方法:
通过手工HttpWebRequest,HttpWebResponse来模拟调用。
核心代码:
string strurl="http://localhost:21696/service1.asmx/getmythod?aa=1";
HttpWebRequest request=(HttpWebRequest) WebRequest.Creates(strurl);
//request.Method="get"
HttpWebResponse response=(System.Net.HttpWebResponse)request.GetResponse();
Stream s=response.GetResponseStream();
XmlTextReader Reader=new XmlTextReader(s);
Reader.MoveToContent();
string strValue=Reader.ReaderInnerXml();
strValue=strValue.Replace("<","<");
strValue=strValue.Replace(">",">");
Regex rx=new Regex(@"(\r\n+)");
strValue =rx.Replace(strValue,"");
div1.InnerHtml=strValue;
Reader.Close();
注意事项:webservice所在的web.config里面要添加:
<webServices>
<protocols>
<add name="HttpPost"/>
<add name="HttpGet"/>
</protocols>
</webServices>
安全风险增加