Листинг 1. Код Web-сервиса
<%
Response.ContentType = "text/xml"
'--------------------------------------
' Web Service Provider
'
' Parameters:
'
' Amount = Amount to convert
' From = Source Currency
' To = Target Currency
'--------------------------------------
Sub AddSubNode(Parent, Name, Value)
Set subNode = XMLDoc.createElement(Name)
Parent.appendChild(subNode)
subNode.appendChild(XMLDoc.createTextNode(Value))
End Sub
Amount = Request.QueryString("Amount")
CurrFrom = Request.QueryString ("From")
CurrTo = Request.QueryString ("To")
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "SQLOLEDB"
ProvStr = "Server=jupiter;Database=WebDemo;Trusted_Connection=yes"
Conn.Open ProvStr
Set RS = Server.CreateObject("ADODB.Recordset")
Query = "SELECT * FROM Curr WHERE Curr='" & CurrFrom & _
"' OR Curr='" & CurrTo & "'"
RS.ActiveConnection = Conn
RS.Source = Query
RS.Open
DataTo = RS("USDUnit")
RS.MoveNext
DataFrom = RS("USDUnit")
RS.Close
Conn.Close
Set Conn = Nothing
Result = FormatNumber(Amount * (DataFrom / DataTo), 2)
' Начнем создавать XML-документ
Set XMLDoc = Server.CreateObject("Microsoft.XMLDOM")
Set pi = XMLDoc.createProcessingInstruction("xml",
" version=""1.0"" encoding=""Windows-1252""")
XMLDoc.appendChild(pi)
' Главная ветвь
Set mainNode = XMLDoc.createElement("conversion")
XMLDoc.appendChild(mainNode)
AddSubNode mainNode, "from", CurrFrom
AddSubNode mainNode, "to", CurrTo
AddSubNode mainNode, "amount", Amount
AddSubNode mainNode, "result", Result
AddSubNode mainNode, "usdFrom", DataFrom
AddSubNode mainNode, "usdTo", DataTo
AddSubNode mainNode, "rate", FormatNumber(DataFrom / DataTo, 4)
AddSubNode mainNode, "text", CStr(Amount) & " " & CurrFrom & _
" = " & Result & " " & CurrTo
Response.Write XMLDoc.XML
Set mainNode = Nothing
Set XMLDoc = Nothing
%>