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)
stefli's MP3: http://stefli.88ip.net/Flex/mp3Player.swf
本文地址:http://com.8s8s.com/it/it42783.htm