Remote call using XML-RPC

xiaoxiao2021-03-06  136

XML-RPC can be seen as a web service simplified version, and their difference is that SOAP can be complicated, while XML-RPC calls can only pass simple types, such as String, Int, Double, Boolean, Byte [], String [].

XML-RPC calls simple, especially compared to EJB remote calls, the client must use the server's Home / Remote interface file. And the file must be completely consistent with the server, otherwise it will be wrong, so when the interface changes or interface decreases, it becomes very troubles, because my EJB remote call application's key business, so I It is generally rarely changed on the original EJB interface, and if the new interface is placed, the remote call is wrong because the version is inconsistent, it is very bad, even if it can be solved in half an hour, it will also cause a small Loss, and the company cannot promise for half an hour to suspend business. So I usually use Web Service or XML-RPC because the client does not need to rely on the server's interface file, so it will not cause the client and server-side call interface inconsistent.

XML-RPC is a POST method based on an HTTP protocol, and the transmitted data is encoded with XML. The XML-RPC call is divided into client and server, and the server side can create a small Webserver or use the Webserver like Tomcat. Below is the server's code: public void init () throws servletexception {xmlrpcserver XMLRPC = New XmlRpcServer (); xmlrpc.addHandler ( "hello", new HelloHandle ());} public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {XmlRpcServer xmlrpc = new XmlRpcServer (); xmlrpc.addHandler ( "hello", new HelloHandle ()); byte [] result = xmlrpc.execute (request.getInputStream ()); response.setContentType ( "text / xml"); OutputStream out = response.getOutputStream (); out.write (result); out .flush ();} public class hellohandle {public string selfhhello (string name) {string str = "Hello" name; system.out.println (str); returnction str;}}

Client code: Xmlrpc.SetDriver ("org.apache.xerces.Parsrs.saxparser"); XmlrpcCCCCCCCLIENT ("http://192.168.11.177:8080/xmlrpc");

Vector params = new vector (); params.addelement ("Hi Everyone!"); String Result = (String) Client.execute ("Hello.sayhello", params); required package: XMLRPC-1.2-b1.jar Xerces .jar to XML-RPC site to download it

转载请注明原文地址:https://www.9cbs.com/read-127222.html

New Post(0)