• C# 通过 Hessian服务调用java


    1.下载Hessiancsharp.dll

    2.新建一个c#窗体程序,然后在添加一个类库

    3.添加一个接口类,接口中的方法名和参数与java中的服务方法名和参数保持一致

      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);
        }
    View Code

    4.引用Hessiancsharp.dll

    5.通过hessian调用java

        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("同步成功!");
            }
    }
    View Code

    参考:http://hessian.caucho.com/

    https://sourceforge.net/projects/hessiancsharp/

    http://www.cnblogs.com/lxsfg/archive/2008/08/27/1277777.html

            

  • 相关阅读:
    [XNA]2D图形概要(2D Graphics Overview)
    [WP7]WindowsPhone支持VS2010的开发工具出来了
    [WM]用双缓冲在CStatic上面画
    [读书]至理名言摘自你的灯还亮着吗
    无题!!
    Windows 8 Consumer Preview 中的快捷键
    aptana studio 汉化与安装 zencoding、配置
    jQuery常用焦点图,可做选项卡切换
    jQuery 导航点击变换样式
    原生JS:焦点图 左右滚动
  • 原文地址:https://www.cnblogs.com/ZJ199012/p/5801930.html
Copyright © 2020-2023  润新知