C# 通过 Hessian服务调用java
2.新建一个c#窗体程序,然后在添加一个类库
3.添加一个接口类,接口中的方法名和参数与java中的服务方法名和参数保持一致
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public partial interface HessianManager { /// <summary> /// /// </summary> /// <param name="method">方法名</param> /// <param name="operate">操作(添加、删除、修改)</param> /// <param name="json">json数据</param> /// <returns></returns> string synchronizeData(string method, string operate, string json); string sayHello(string msg); }
4.引用Hessiancsharp.dll
5.通过hessian调用java
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public partial class frmHessian : Form { string url = ConfigurationManager.AppSettings["url"].ToString(); CHessianProxyFactory factory = new CHessianProxyFactory(); HessianManager hessianClient = null; public frmHessian() { InitializeComponent(); hessianClient = (HessianManager)factory.Create(typeof(HessianManager), url); } /// <summary> /// 同步供应商 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSynSupplier_Click(object sender, EventArgs e) { List<Supplier> supplists = new List<Supplier>(); DataTable dt = DbHelperSQL.Query("SELECT * FROM dbo.Sys_Supplier WHERE ss_State=1").Tables[0]; foreach (DataRow item in dt.Rows) { Supplier sup = new Supplier(); sup.bbbpSn = item["ss_SupplierNo"].ToString(); sup.bbbpId = item["ss_SupplierNo"].ToString(); sup.bbbpBbbrId = 1; sup.bbbpName = item["ss_SupplierName"].ToString(); sup.bbbpContact = item["ss_Contact"].ToString(); sup.bbbpContactTel = item["ss_Tel"].ToString(); sup.bbbpContactPhone = item["ss_Phone"].ToString(); sup.bbbpContactAddress = item["ss_Adress"].ToString(); sup.bbbpState = Convert.ToInt32(item["ss_State"]) == 1 ? "有效" : "无效"; sup.bbbpLocationid = 5001; //item["sp_PurchaserNo"] == DBNull.Value ? 5001 : Convert.ToInt32(item["sp_PurchaserNo"]); sup.bbbpYingfu = 0; sup.bbbpIds = ",1,"; sup.bbbpBank = item["ss_Bank"].ToString(); sup.bbbpBankNumber = item["ss_BankAccount"].ToString(); sup.bbbpGongyingjiezhiDate = string.Format("{0:yyyy-MM-dd HH:mm:ss}", item["ss_BusiLicexpireTime"]); sup.bbbpFaxNumber = item["ss_Fax"].ToString(); supplists.Add(sup); } string msg = hessianClient.synchronizeData("synBusinessParter", "add", JsonHelper.SerializeObject(supplists)); Application.DoEvents(); MessageBox.Show("同步成功!"); } }
参考:http://hessian.caucho.com/
https://sourceforge.net/projects/hessiancsharp/
http://www.cnblogs.com/lxsfg/archive/2008/08/27/1277777.html
posted on 2016-08-24 10:39 lovezj9012 阅读(946) 评论(0) 编辑 收藏 举报