【IT168技术文档】
Hessian其实很像web service,只不过它的协议不是SOAP,而是它自己规定的binary协议。Hessian的server端提供一个servlet基类, client端获得一个service接口(也就是stub)之后调用上面的方法,stub将方法调用marshal之后通过HTTP传到server, server借助reflection调用service方法。
先到http://www.hessiancsharp.org上去下载一个DLL文件(或者直接下载我的Demo,里面有dll和源代码文件),具体源码
第一步:java的设置,简单列举几个类(至于要怎么实现可以看这篇文章)
1 服务
2 实体类 CmsContentpublic class HessionServiceImpl implements IHessionService { private ICmsService cmsService; public String getHelloWorld() { return "Hello World"; } /**//* (non-Javadoc) * @see com.digitalchina.dcis.domain.service.IHessionService#getStringList() */ public List getStringList() { List list = new ArrayList(); list.add("duck"); list.add("fish"); return list; } public List getCmsContentListByLabel(String label,int num){ return this.cmsService.getCmsContentListByLabel(label, num); } /**//** * @param cmsService the cmsService to set */ public void setCmsService(ICmsService cmsService) { this.cmsService = cmsService; } }
public class CmsContent implements Serializable { public static String PROP_TITLE = "title"; public static String PROP_CONTENT = "content"; public static String PROP_ID = "id"; // constructors public CmsContent () { initialize(); } protected void initialize () {} private int hashCode = Integer.MIN_VALUE; // primary key private java.lang.String id; // fields private java.lang.String title; private java.lang.String content; /**//** * Return the unique identifier of this class * @hibernate.id * generator-class="uuid.hex" * column="ID" */ public java.lang.String getId () { return id; } /**//** * Set the unique identifier of this class * @param id the new ID */ public void setId (java.lang.String id) { this.id = id; this.hashCode = Integer.MIN_VALUE; } /**//** * Return the value associated with the column: TITLE */ public java.lang.String getTitle () { return title; } /**//** * Set the value related to the column: TITLE * @param title the TITLE value */ public void setTitle (java.lang.String title) { this.title = title; } /**//** * Return the value associated with the column: CONTENT */ public java.lang.String getContent () { return content; } /**//** * Set the value related to the column: CONTENT * @param content the CONTENT value */ public void setContent (java.lang.String content) { this.content = content; } public int hashCode () { if (Integer.MIN_VALUE == this.hashCode) { if (null == this.getId()) return super.hashCode(); else { String hashStr = this.getClass().getName() + ":" + this.getId().hashCode(); this.hashCode = hashStr.hashCode(); } } return this.hashCode; } public String toString () { return super.toString(); } }