zoukankan      html  css  js  c++  java
  • 搞定2个问题:C# 动态调用java webservice,Winform解析Json字符串中特殊值

    FAQ:

    1、最近做的项目需要和Java做的系统的webservice交互数据.一上来直接添加web引用,一路OK。但是地址在发布时要变的,以为也简单,其实不然,改了app.config里的配置,调用代理类的方法,结果一直不变。郁闷了。google了一把解决了。原来不能直接实例化代理类。需要如下处理:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using GB_PRINT.com.goodbabygroup.factorybarcode_sayHi;
    using GB_PRINT.com.goodbabygroup.factorybarcode;
    using GB_PRINT.com.goodbabygroup.factorybarcode_Login;

    namespace GB_PRINT
    {
    /// <summary>
    /// HelloWorld动态代理类
    /// </summary>
    public class wsHelloWorldProxy : HelloWorld
    {
    public wsHelloWorldProxy(string url)
    {
    this.Url = "http://" + url + "/ws/webservice/helloWorld";
    }
    }

    /// <summary>
    /// StoreProcedure动态代理类
    /// </summary>
    public class wsStoreProcProxy : StoreProcedure
    {
    public wsStoreProcProxy(string url)
    {
    this.Url = "http://" + url + "/ws/storeProcedure";
    }
    }

    /// <summary>
    /// StoreProcedure动态代理类
    /// </summary>
    public class wsLoginProxy : CsLoginService
    {
    public wsLoginProxy(string url)
    {
    this.Url = "http://" + url + "/ws/csLogin";
    }
    }
    }

    2、Json数据的解析。

    string result =@"{"Own_Gp_Num_Id":"13633","Empe_Name":"推车一厂","Message":"登录成功","Empe_Id":"500001","ORG_NO_Value":"儿童用品有限公司推车一厂-打印中心","SubEntity_Name":"儿童用品有限公司推车一厂","ENTITY_NAME":"儿童用品有限公司推车一厂","CLIENT_MAC":"cb159d4b7eadf88166bc0e6ff23f5314","popedomInfo":[ ],"Cort_Num_Id":"9586","Code":"0","ORG_NO_ID":"6"}";

    popedomInfo":[ ],"在Json里面代码个数组。我刚开始使用第一个版本的类去接,老是报什么"System.String"什么转换错误,后来发现js里面[]代表一个数组。修改后成功。

    第一版的:

    /// <summary>
    /// 用户实体DTO
    /// </summary>
    public class LocalUserEntity
    {
    public string Own_Gp_Num_Id
    {
    get;
    set;
    }
    public string Empe_Name
    {
    get;
    set;
    }
    public string Empe_Id
    {
    get;
    set;
    }
    public string ORG_NO_Value
    {
    get;
    set;
    }
    public string SubEntity_Name
    {
    get;
    set;
    }
    public string ENTITY_NAME
    {
    get;
    set;
    }
    public string CLIENT_MAC
    {
    get;
    set;
    }
    public string popedomInfo
    {
    get;
    set;
    }
    public long Cort_Num_Id
    {
    get;
    set;
    }
    public long ORG_NO_ID
    {
    get;
    set;
    }

    public string Code
    {
    get;
    set;
    }

    public string Message
    {
    get;
    set;
    }
    }

    第二版:

    /// <summary>
    /// 用户实体DTO
    /// </summary>
    public class LocalUserEntity
    {
    public string Own_Gp_Num_Id
    {
    get;
    set;
    }
    public string Empe_Name
    {
    get;
    set;
    }
    public string Empe_Id
    {
    get;
    set;
    }
    public string ORG_NO_Value
    {
    get;
    set;
    }
    public string SubEntity_Name
    {
    get;
    set;
    }
    public string ENTITY_NAME
    {
    get;
    set;
    }
    public string CLIENT_MAC
    {
    get;
    set;
    }
    public int [] popedomInfo
    {
    get;
    set;
    }
    public long Cort_Num_Id
    {
    get;
    set;
    }
    public long ORG_NO_ID
    {
    get;
    set;
    }

    public string Code
    {
    get;
    set;
    }

    public string Message
    {
    get;
    set;
    }
    }


    调用:

    LocalUserEntity result = null;
    try
    {
    jsonData_str = Program.csLogin.csLogin(vParam);
    result = JsonConvert.DeserializeObject<LocalUserEntity>(jsonData_str);
    }
    catch (Exception ex)
    {
    throw ex;
    }
    //假装授权
    result.popedomInfo = new int[] { 1,2,3 };
    if (result.Message.Equals("登录成功"))
    {
    if (result.popedomInfo.Length > 0)
    {
    foreach(int popedomValue in result.popedomInfo)
    {
    ClientPopedom value = (ClientPopedom)Enum.Parse(typeof(ClientPopedom), popedomValue.ToString());
    LocalPopedom.m_LocalPopedom.clientPopedom.Add(value);
    }
    }
    }

    记录下来备忘,也给遇到同样问题的朋友一个很逊的方案。 


    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    "作者:" 数据酷软件工作室
    "出处:" http://datacool.cnblogs.com
    "专注于CMS(综合赋码系统),MES,WCS(智能仓储设备控制系统),WMS,商超,桑拿、餐饮、客房、足浴等行业收银系统的开发,15年+从业经验。因为专业,所以出色。"
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  • 相关阅读:
    phpcms二级菜单
    html5 audio JavaScript 点击播放暂停
    jquery获取type=radio属性的值
    github push 出错:fatal: Authentication failed for 'https://github.com/ ..的解决
    win10远程桌面出现身份验证错误的解决方法
    谷歌和火狐浏览器清除缓存快捷键
    JavaScript的动画
    随机颜色的函数
    JQuery写的一个常见的banner
    网页点击跳转到微信页面
  • 原文地址:https://www.cnblogs.com/datacool/p/Josn001797110.html
Copyright © 2011-2022 走看看