tornado
Keywords: XML, HTTP, COM
1. Scalability
The scalability is a measure of how many users can be handled in the same time. It is also an indicator that reflects whether the application meets important applications.
How many users can be accommodated in your application, each user submits a request to the server, where your user is located, such as the local area network or an interner. These problems are required to consider when designing applications.
One problem is the protocol used before design distributed applications. Such as DCOM, HTTP and MSMQ.
The disadvantage of DCOM is significant. If you can't cross the firewall. You cannot use the request-based load balancing technology, thereby limiting the number of concurrent users, but also a lot of configurations for each client.
HTTP achieves simple and support for all platforms. In fact, building a COM architecture is based on this basis: An application must use HTTP to implement the customer's communication to obtain maximum scalability.
2. Actual problem
Often we will encounter such problems, such as a store with multiple branches, requires daily branches to upload business data to the general store. It is far from each other.
The environment of the store: has its own fixed IP web server (or no fixed IP), or there is no own server, just a virtual space website.
The environment of the branch: can be connected by dialing.
3. Request
The store can see the store in a timely manner every day. And the data should be reserved locally.
4. Common solution
One way is that the branch exports data into txt files. After the dial connection is successful, transfer TXT to an FTP directory or send it to the specified email. The general store is manually received or the program is received, and then processes.
There is also a database of databases directly connects to the database's database, making saving update operations.
5. Implement with HTTP and XML
It is the client application to transfer parameters through an XML document, submit an HTTP request to the web server. The server uses an ASP page to get the parameter, perform its method, then use the XML document to return data to the client.
First look at the code of the server ASP:
1). Return data from the server
GetInfo.asp (return to records in a stream)
<% @ Language = VBScript%>
<%
Set conn = server.createObject ("adoDb.connection")
Conn.open "driver = {Microsoft Access Driver (* .mdb)}; dbq =" & Server.mappath ("Web.mdb")
DIM RS
SET RS = Server.createObject ("AdoDb.Recordset")
Rs.Open "Select * from test", conn
Rs.save response, 1
Rs.close
%>
Here, it will be described here: as long as the client sends a format XML document, the request and response objects in the ASP will work. (This technology can only be used in IIS5 and Windows 2000 and its own high versions.)
Use VB in the client
'Quote Microsoft ActiveX Data Object 2.x Library
'Quote Microsoft XML, Version 2.0
Option expedition
Private rs as adodb.recordset
'Get content from remote database
Private sub fascist5_click ()
'Submit an HTTP request.
SET RS = New Adodb.Recordset
rs.open "http://localhost/webxml/getinfo.asp" set dataGrid1.datasource = rs
End Sub
2) Submit to remote ASP files
Getsingleinfo.asp (data increased and returned)
<% @ Language = VBScript%>
<%
'Here you need to modify, return to the client's XML response document
Response.contentType = "text / xml"
Set conn = server.createObject ("adoDb.connection")
Conn.open "driver = {Microsoft Access Driver (* .mdb)}; dbq =" & Server.mappath ("Web.mdb")
DIM XMLDOM
'set Xmldom = Server.createObject ("Microsoft.xmldom")
SET XMLDOM = Server.createObject ("msxml.domdocument")
XMLDom.Load Request
DIM SID, Name, Price, Catagory, PDATE
SID = XmLDom.selectsinglenode ("// project number) .Text
Name = xmldom.selectsinglenode ("// project name") .Text
Price = xmldom.selectsinglenode ("// price") .Text
Catagory = xmldom.selectsinglenode ("// Type") .Text
pdate = xmldom.selectsinglenode ("// Create Date") .Text
DIM STRSQL, RETVAL
ON Error ResMe next
Strsql = "INSERT INTO TEST (SID, Name, Price, Catagory, PDATE) VALUES ('" & SID & ",'" & Name & ", '" & Price & ",'" & Catagory & "' , '"& pdate &") "
'Response.write strsql
Conn.execute strsql
IF err.number = 0 THEN
Retval = "Data Success Submit"
Else
RETVAL = "Data submission failed, please check your data"
END IF
Set xmldom = Nothing
Set conn = Nothing
'The following code is to return the result in the form of XML
'Need to add XML Version = "1.0" encoding = "GB2312"?> This, otherwise you can't return Chinese.
%>
XML Version = "1.0" encoding = "GB2312"?>
Response>
Corresponding client VB code: private submmand3_click ()
DIM HTTPREQUEST AS MSXML.XMLHTTPREQUEST
Set httpRequest = new msxml.xmlhttpRequest
DIM STRXML AS STRING
'Constructing the XML string to upload, here nodes use Chinese
Strxml = "
"
"
"<" "& Txtpdate.text &" "" "& _
" Request>"
HttpRequest.open "Post", "http://localhost/webxml/putsingleinfo.asp", false
HttpRequest.send strXML
'If it is wrong
IF httpRequest.status <> 200 then
Msgbox httprequest.statustext, httprequest.status
EXIT SUB
END IF
'The following is to determine if the data is properly submitted
Dim Strretval as string
Dim Responsexml as DomDocument
SET Responsexml = New DomDocument
Set responsexml = httpRequest.responsexml
Strretval = responsexml.selectsinglenode ("// RetVal"). Text
MSGBOX STRETVAL
End Sub
3) Multiple data upload
Putinfo.asp
<% @ Language = VBScript%>
<%
Response.contentType = "text / xml"
Set conn = server.createObject ("adoDb.connection")
Conn.open "driver = {Microsoft Access Driver (* .mdb)}; dbq =" & Server.mappath ("Web.mdb")
DIM RS
ON Error ResMe next
SET RS = Server.createObject ("AdoDb.Recordset")
DIM XMLDOM
'set Xmldom = Server.createObject ("Microsoft.xmldom")
Set Xmldom = Server.createObject ("msxml.domdocument") xmldom.load request
DIM SID, Name, Price, Catagory, PDATE
Set XMLNode = XmLDom.documentelement
Set objretvalnode = xmldom.documentelement
For i = 0 to xmlnode.childnodes.length - 1
SID = XMLNode.childNodes (i) .childNodes (0) .Text
Name = xmlnode.childNodes (i) .childNodes (1) .text
Price = xmlnode.childNodes (i) .childNodes (2) .text
Catagory = xmlnode.childnodes (i) .childNodes (3) .text
PDATE = XMLNode.childNodes (i) .childnodes (4) .text
Strsql = "INSERT INTO TEST (SID, Name, Price, Catagory, PDATE) VALUES ('" & SID & ",'" & Name & ", '" & Price & ",'" & Catagory & "' , '"& pdate &") "
'Response.write strsql
Conn.execute strsql
NEXT
IF err.number = 0 THEN
Retval = "Data Success Submit"
Else
RETVAL = "Data submission failed, please check your data"
END IF
Set conn = Nothing
%>
XML Version = "1.0" encoding = "GB2312"?>
Response>
Corresponding VB client code
Private sub fascist2_click ()
DIM RS1 AS New Adodb.Recordset
Rs1.cursorlocation = aduseclient
rs1.cursortype = adopenkeyset
Rs1.lockType = AdlockBatchOptimistic
RS1.Open "Select * from test", conn, adopendynamic, AdlockPESSIMISTIC
'Due to too many things contained in RequestXML, we directly generate an XML file.
'Database field directly, did not use Chinese naming
DIM STRXML
DIM FM
Strxml = "
RS1.Movefirst
Do While Not Rs1.eof
Strxml = strXml & "
For Each FM in rs1.fields
Strxml = strxml & "<" & fm.name & "> & fm.value &" <& fm.name & "" Next
Strxml = strXml & " row>"
RS1.MOVENEXT
Loop
Strxml = strXml & " xml>"
SET RS1 = Nothing
DIM HTTPREQUEST AS New MSXML.XMLHTTPREQUEST
HttpRequest.open "Post", "http://localhost/webxml/putinfo.asp", false
HttpRequest.send strXML
IF httpRequest.status <> 200 then
Msgbox httprequest.statustext, httprequest.status
EXIT SUB
END IF
SET RS = New Adodb.Recordset
'Reload
Rs.open "http://localhost/webxml/getinfo.asp"
SET DATAGRID1.DATASOSOSOSOURCE = RS
'The following is to determine if the data is properly submitted
Dim Strretval as string
Dim Responsexml as DomDocument
SET Responsexml = New DomDocument
Set responsexml = httpRequest.responsexml
Strretval = responsexml.selectsinglenode ("// RetVal"). Text
MSGBOX STRETVAL
End Sub
Conclusion:
This example fully reflects the advantages of HTTP and XML. For customers, you can customize your own XML format, clear and easy to understand. Safety is greatly improved. And it can be extended on a different application server.
If you want to improve performance and increase security, you can use COM components in the server to extend the ASP to achieve the best results.
Download this example full code