- http://blog.gufang.org/
- 2016/3/23 18:00:32
- 来源:Gufang's Private Space
- 点击:115
刚才研究了下怎么用ASP调用WebService,其实调用WebService返回数据很简单,但怎么去请求WebService就不太清楚了。
查了一些资料,试着用SOAP来做请求,同时返回结果,第一次没成功,说是
Set soapclient = server.CreateObject("MSSOAP.SoapClient30") 这行有错误,这肯定就是组件没注册了。
想在找找还有其他的方法没,但让我把SoapToolkit这个东西给找到了,安装上,测试代码,不报错了!!哈哈!!
下面把DEMO发出来,大家参考下吧
用.NET做了个简单的WebService。代码如下:
[WebMethod]
public string Show(string name, string pass)
{
if (name == "aaa" && pass == "123")
return "成功!";
else
return "失败!";
}
ASP做了个页面请求并返回结果
<form id="form1" name="form1" method="post" action="">
<input type="text" name="name" id="name" />
<input type="text" name="pass" id="pass" />
<input type="submit" name="button" id="button" value="提交" />
</form>
<%
if request("button")<>"" then
dim strName,strPass
strName = request("name")
strPass = request("pass")
Set xmldoc = server.createObject("Msxml2.DOMDocument")
xmldoc.async = false
Set soapclient = server.CreateObject("MSSOAP.SoapClient30")
soapclient.ClientProperty("ServerHTTPRequest") = True
soapclient.mssoapinit "http://localhost:8008/WebService.asmx?wsdl","","",""
str = soapclient.Show(strName,strPass)
response.Write str
end if
%>
OK,成功了!!