asp调用 web service

coveking 2006-04-25 11:52:16
这是我的源码

Set objHTTP = Server.CreateObject("MSXML2.XMLHTTP")
Set xmlDOC =Server.CreateObject("Microsoft.XMLDOM")
strWebserviceURL = "http://webserver.wzilin.com/webserver/WS_BIG5/qq.asmx?op=CHINA_Weather"
'设置参数及其值
strRequest = "x="&request.Form("a")&"&y="&request.Form("b")
objHTTP.Open "POST", strWebserviceURL, False
objHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objHTTP.Send(strRequest)
bOK = xmlDOC.load(objHTTP.responseXML)
'看看状态值
if objHTTP.Status=200 then


Set docXSL = server.CreateObject("Microsoft.XMLDOM")
docXSL.async = False
docXSL.load(server.MapPath("test1.xsl"))
'response.write docXSL.xml

Set docTran = server.CreateObject("Microsoft.XMLDOM")
xmlDOC.transformNodeToObject docXSL,docTran
'response.write docTran.xml

xmlStr = docTran.xml
xmlStr = Replace(xmlStr,"<","<",1,-1,1)
xmlStr = Replace(xmlStr,">",">",1,-1,1)
response.write xmlStr
end if

报错:Server.CreateObject 失败
无效的 ProgID。 若要获取关于此消息的更多的信息,请访问 Microsoft 联机支持站点: http://www.microsoft.com/contentredirect.asp 。
我不知道用asp怎么去调用wen service这个是我在网上找的例子.
请教各位大侠我要怎么才能把天气预报这个web service的内容取出来啊.提供代码给我学习吧.
...全文
183 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
coveking 2006-04-25
  • 打赏
  • 举报
回复
在[行2]就报错了.好像是不能创建Set xmlDOC =Server.CreateObject("Microsoft.XMLDOM")
很明显作为SOAP不能用在客户端,所以只能用XML来解析的.
是是非非 2006-04-25
  • 打赏
  • 举报
回复
测试时发现几个错误,已修正
代码在这里下载

http://www.eglic.com/Scripts/newSoap.vbs

===================================
报错:Server.CreateObject 失败
这个可能是因为服务器没有安装 MSXML 或者 管理员没有给予 MSXML 组件的权限
是是非非 2006-04-25
  • 打赏
  • 举报
回复
SOAP类代码见 http://blog.csdn.net/eglic/archive/2005/11/28/538445.aspx

=============================
Dim app : Set app=New SOAPInstance
app.IgnoreReturnValue=True
app.URL="http://webserver.wzilin.com/webserver/WS_BIG5/qq.asmx"
app.WebMethod("IP")("ip_add").Value="211.99.196.22"
On Error Resume Next
Dim ret : Set ret=app.WebMethod("IP").Invoke()
If Err.Number<>0 Then
MsgBox Err.Description,64,"服务器返回错误"
Err.Clear
Else
MsgBox ret.ToString(),64,TypeName(ret)
End If
On Error Goto 0
Set app=Nothing
MsgBox "执行完毕"
是是非非 2006-04-25
  • 打赏
  • 举报
回复
在哪一行错误?
btlyeo 2006-04-25
  • 打赏
  • 举报
回复
这段代码没错,这个页面有没有和读取注册表有关系的地方,你那里写的正确不?或者调用这些方法的的函数写对没?
sxsgssgs 2006-04-25
  • 打赏
  • 举报
回复
你分开做。
先用MSXML2.XMLHTTP取得字符串

然后用xmldom对字符串进行解析。
xxuu503 2006-04-25
  • 打赏
  • 举报
回复
我写的JS版的

很简单,你翻vbs就可以了
xxuu503 2006-04-25
  • 打赏
  • 举报
回复
var NameSpace = 'http://tempuri.org/'

function CreateParam(ParamName,ParamValue)
{
var Param = ''
Param += '<' + ParamName + '>'
Param += ParamValue
Param += '</' + ParamName + '>'
return Param
}

function CreateSoapRequest(MethodName,Params)
{
var SoapRequest = ""
var IntTemp
SoapRequest += '<?xml version=\"1.0\" encoding=\"utf-8\"?>'
SoapRequest += '<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" '
SoapRequest += 'xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" '
SoapRequest += 'xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">'
SoapRequest += '<soap:Body>'
SoapRequest += '<' + MethodName + ' xmlns=\"' + NameSpace + '\">'
if(Params != undefined)
{
for(IntTemp = 0 ; IntTemp < Params.length ; IntTemp++)
{
SoapRequest += Params[IntTemp]
}
}
SoapRequest += '</' + MethodName + '>'
SoapRequest += '</soap:Body>'
SoapRequest += '</soap:Envelope>'
return SoapRequest
}

function WebService()
{
this.XmlHttp = new ActiveXObject("Msxml2.XMLHTTP")
this.GetResponse = function(Url,MethodName,Params)
{
var SoapRequest = CreateSoapRequest(MethodName,Params)
this.XmlHttp.Open("POST",Url,false)
this.XmlHttp.setRequestHeader("Content-Type", "text/xml;charset=utf-8")
this.XmlHttp.setRequestHeader("Content-Length",SoapRequest.length)
this.XmlHttp.setRequestHeader("SOAPAction", NameSpace+MethodName)
this.XmlHttp.send(SoapRequest)
}
}
coveking 2006-04-25
  • 打赏
  • 举报
回复
eglic(圪圪) 你的公共函数用了,不管用.请关注一下
coveking 2006-04-25
  • 打赏
  • 举报
回复
现在是 response.Write(objHTTP.Status) = 500
这样的话就说明这个web service 的 Net Framework1.1默认不支持HttpGet和HttpPost。要修改其webservice里的web.config?

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧