I haven't been engaged in VB6 for two years. I have been switching to PhP and python, but I have always missed that time, so I cannot give up on his simplicity and practicality. Due to the relationship between projects, I often use VB6,
For this reason, I also share some of my app's joy.
XML-RPC(What is XML-RPC? Here I will not provide many professional instructions. You can use Baidu.) It is actually very useful and simple and practical, in some small projects, we can make excellent performance. VB6 can be combined with XML-RPC to connect to the backend Web server. It can be said that it is perfect, and it can be combined with my current project.
Turning words right,
Requirement Analysis:
1. The client was previously written in VB6 and now needs to access external network data (such as obtaining real-time foreign exchange rates), but does not want to open the Internet access permission to your client
2. Currently, one web server is Apache + PHP or Python.
3. Because the programs written in VB6 didn't want to convert them all into webpages (because this is a big project)
Solution:
(1) PHP is a backend Web Service Language solution: (Server Installation, I will not talk about it here)
Download the XML-RPC for PHP first, decompress it and put it under the root directory of your server web page, for the background XML-RPC service,
Now you can execute: http: // localhost/XMLRPC/debugger/index. php on the server,
Address: localhost, path:/XMLRPC/demo/Server/server. PHP: select list available methods. After you click execute, you can see the result, which indicates that you can use the XML-RPC service.
(2) solutions for using python as the background Web Service language:
Python itself supports XML-rpc. Here I will write a simple server example:
from xmlrpc.server import SimpleXMLRPCServerfrom xmlrpc.server import SimpleXMLRPCRequestHandler# Restrict to a particular path.class RequestHandler(SimpleXMLRPCRequestHandler): rpc_paths = ('/RPC2',)# Create serverserver = SimpleXMLRPCServer(("localhost", 8000), requestHandler=RequestHandler)server.register_introspection_functions()# Register pow() function; this will use the value of# pow.__name__ as the name, which is just 'pow'.server.register_function(pow)# Register a function under a different namedef adder_function(x,y): return x + yserver.register_function(adder_function, 'add')# Register an instance; all the methods of the instance are# published as XML-RPC methods (in this case, just 'mul').class MyFuncs: def mul(self, x, y): return x * yserver.register_instance(MyFuncs())# Run the server's main loopserver.serve_forever()
Save as rpc. py file on the server, double-click to execute OK
(3) how to connect the client VB6 to the Web server
1) download two DLL files: vbxml. dll and vbxmlrpc. dll, which are the XML-RPC parsing tool libraries respectively. download the files here (the original code is also provided)
Http://www.enappsys.com/backend/vbXMLRPC/vbXMLRPCBinaries.jsp
2) Register com
Regsvr32/s vbxml. dll
Regsvr32/s vbxmlrpc. dll
3.) referenced in VB6, as shown in figure
4.) How to Write VB6 client code, such
Option ExplicitPrivate Sub Command_Click() Dim vRequest As New XMLRPCRequest Dim vResponse As XMLRPCResponse Dim vUtility As New XMLRPCUtility Me.MousePointer = vbHourglass Set vRequest = GetPYRpc("add") vRequest.Params.AddInteger Text1.Text vRequest.Params.AddInteger Text2.Text 'Debug.Print vRequest.XMLToSend Set vResponse = vRequest.Submit Select Case vResponse.Status Case XMLRPC_PARAMSRETURNED If vResponse.Params.Count = 1 Then Debug.Print vResponse.HTTPHeaders Debug.Print vResponse.XMLResponse Text3.Text = vResponse.Params(1).IntegerValue Else BugOut "Expecting one return parameter, received '" & vResponse.Params.Count & "'." End If Case XMLRPC_FAULTRETURNED BugOut "Server returned a fault. Code is '" & vResponse.Fault.FaultCode & "', description is '" & vResponse.Fault.FaultString & "'." Case XMLRPC_HTTPERROR BugOut "HTTP error encountered. Code is '" & vResponse.HTTPStatusCode & "', description is '" & vUtility.GetHTTPError(vResponse.HTTPStatusCode) & "'." Case XMLRPC_XMLPARSERERROR BugOut "XML Parsing Error encountered '" & vResponse.XMLParseError & "'." Case XMLRPC_NOTINITIALISED BugOut "Weird, the response claims not to be initialised !!!" Case Else BugOut "Double Weird, unknown response status '" & vResponse.Status & "'." End Select Me.MousePointer = vbDefaultEnd SubPrivate Sub BugOut(ByVal vstrError As String) MsgBox vstrError, vbOKOnly + vbCritical, App.TitleEnd Sub
Option ExplicitPublic Function GetPHPRpc(ByVal vMethod As String) As XMLRPCRequestDim mReq As XMLRPCRequestSet mReq = New XMLRPCRequest mReq.ConnectTimeOut = 60 mReq.ReceiveTimeOut = 60 mReq.SendTimeOut = 60 mReq.HostName = "localhost" mReq.HostPort = 80 mReq.HostURI = "/xmlrpc/demo/server/server.php" mReq.MethodName = vMethodSet GetPHPRpc = mReqEnd FunctionPublic Function GetPYRpc(ByVal vMethod As String) As XMLRPCRequestDim mReq As XMLRPCRequestSet mReq = New XMLRPCRequest mReq.ConnectTimeOut = 0 mReq.ReceiveTimeOut = 0 mReq.SendTimeOut = 120 mReq.HostName = "localhost" mReq.HostPort = 8000 mReq.HostURI = "/RPC2" mReq.MethodName = vMethodSet GetPYRpc = mReqEnd Function
The test result is as follows: