首页 > 编程 > ASP > 正文

使用HTTPService与Asp的伪Web服务通讯,完成数据库操作

2024-05-04 11:06:39
字体:
来源:转载
供稿:网友
使用httpservice与asp的伪web服务通讯,完成数据库操作

我提供一个asp的伪服务思想:

clientreq.xml:
-------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="gb2312"?>
<testpacket>
<msgtype>getvaluereq</msgtype>
<version>1.0</version>
</testpacket>


index.mxml:
-------------------------------------------------------------------------------------------------
<mx:model id="mreq" source="clientreq.xml"/>
<mx:httpservice id="hs" url="http://asp/testserver.asp"
resultformat="xml"
method="post"
contenttype="application/xml"
showbusycursor="true">
<mx:request>
<xml>{mreq}</xml>
</mx:request>
</mx:httpservice>


testserver.asp:
-------------------------------------------------------------------------------------------------
主要有获得数据包,解析数据包,指定操作,返回数据四步

1。获得提交的数据包
set odom = server.createobject("msxml2.domdocument")
odom.load request

2。解析数据包,获得msgtype
smsgtype = trim(odom.selectsinglenode("//msgtype").text)
select case smsgtype
case "getvaluereq"
call getvalue
'case "deletevaluereq"
' call deletevalue
case "insertvaluereq"
' call insertvalue(odom)
'case "updatevaluereq"
' call updatevalue
'else case
' call showerrmsg
end select

3。指定操作,此处完成getvalue操作,其中有很多可以做成公共的模块供其他函数使用
sconn = "driver={microsoft access driver (*.mdb)};dbq=" & server.mappath("message.mdb")
set oconn = server.createobject("adodb.connection")
oconn.open sconn
ssql = "select * from message order by id desc"
set ors = server.createobject("adodb.recordset")
ors.open ssql, oconn, 1, 1

'构造无记录xml文档
if ors.eof and ors.bof then
sxml = "<?xml version=""1.0"" encoding=""gb2312""?>" & vbcrlf &_
"<testpacket>" & vbcrlf &_
" <msgtype>systemresp</msgtype>" & vbcrlf &_
" <version>1.0</version>" & vbcrlf &_
" <result>0</result>" & vbcrlf &_
"</testpacket>"
end if

'构造有记录xml文档
if not (ors.eof and ors.bof) then
do while not ors.eof
stmpxml = stmpxml & "<messages>" & vbcrlf &_
"<name>" & ors("name") & "</name>" & vbcrlf &_
"<age>" & ors("age") & "</age>" & vbcrlf &_
"<sex>" & ors("sex") & "</sex>" & vbcrlf &_
"<msg>" & ors("msg") & "</msg>" & vbcrlf &_
"</messages>" & vbcrlf
ors.movenext
loop
sxml = "<?xml version=""1.0"" encoding=""gb2312""?>" & vbcrlf &_
"<testpacket>" & vbcrlf &_
" <msgtype>systemresp</msgtype>" & vbcrlf &_
" <version>1.0</version>" & vbcrlf &_
" <result>1</result>" & vbcrlf & stmpxml &_
"</testpacket>"
end if

4.返回数据
set odom = server.createobject("msxml2.domdocument")
odom.loadxml(sxml)
odom.save(response)
set odom = nothing


message.mdb
-------------------------------------------------------------------------------------------------
数据库名:message.mdb
数据表名:message
数据字段:字段 类型
id 自动编号
name 文本
age 数字
sex 文本
msg 备注


执行结果:
-------------------------------------------------------------------------------------------------
我是设置httpservice的resultformat="text"时,看显示的结果



本主题包含附件: sf_2004111813537.jpg (23359bytes)







csdn blog: http://blog.csdn.net/stefli

stefli's mp3: http://stefli.88ip.net/flex/mp3player.swf


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表