phprpc是一个轻型的、安全的、跨网际的、跨语言的、跨平台的、跨环境的、跨域的、支持复杂对象传输的、支持引用参数传递的、支持内容输出重定向的、支持分级错误处理的、支持会话的、面向服务的高性能远程过程调用协议。
官方主页:http://www.phprpc.org/zh_cn/
官方网站有比较详尽的各种版本的使用介绍,上手还是比较快的。以下给出我的一个demo示例,从看文档到开发第一demo用了30分钟左右。
我使用的是java版本,前面的安装步骤不在重述了,看官方文档。
1.编写service接口及实现类
public interface servicei { public string say(string name); public errors showerror(string info);}
public class firstservice implements servicei{ @override public string say(string name) { string res = hello, +name+ from phprpc; return res; } public errors showerror(string info){ errors er = null; er = new errors(); er.setid(1111); er.setmsg(phprpc make error:+info); return er; }}
public class errors implements serializable{ private string id; private string msg; public errors(){} public string getid() { return id; } public void setid(string id) { this.id = id; } public string getmsg() { return msg; } public void setmsg(string msg) { this.msg = msg; } }
2.通过servlet发布服务
public class phprpcgloabservice extends httpservlet { @override protected void service(httpservletrequest req, httpservletresponse res) throws servletexception, ioexception { [b]phprpc_server server = new phprpc_server(); firstservice first = new firstservice(); server.add(first); server.start(req, res);[/b] } }
配置web.xml文件,将要发布的服务都置于rpcservice空间下
gloabservice com.smartcoms.service.phprpcgloabservice 1gloabservice/rpcservice/*
服务发布完毕!
3、编写客户端程序
我以jsp页面做客户端访问service
phprpc 调试
phprpc使用起来还是很简单的,可以实现快速web service应用。其它方面,还有待在更多的应用环境下实施和评估。
