WPF参数传入【Java接收】

一、JSON传值

wpf——>Java后台
JSON传值格式【WPF】(post)

 public async Task<ServiceResponse> CancleM(RevokeBatchParam revokeBatchParam)
        {
            HttpClient httpClient0 = new HttpClient();
            try
            {
                httpClient0.DefaultRequestHeaders.Add("Authorization", "Bearer " + this.token);
                List<KeyValuePair<string, string>> param = new List<KeyValuePair<string, string>>();
                param.Add(new KeyValuePair<string, string>("revokeBatchParamStr", JsonConvert.SerializeObject(revokeBatchParam)));
                Task<HttpResponseMessage> responseMessage = httpClient0.PostAsync(TQT.ServerBusiness.Properties.Resources.Http_Api + "services/servicepl/api/manufOrd/cancleMergBatch", new FormUrlEncodedContent(param));
                responseMessage.Wait();
                Task<string> reString = responseMessage.Result.Content.ReadAsStringAsync();
                reString.Wait();
                Newtonsoft.Json.Linq.JObject menuDatas = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(reString.Result);
                var result = menuDatas.GetValue("success").ToString();
                if (result == "False")
                {
                    return new ServiceResponse() { Success = false, Message = menuDatas.GetValue("message").ToString() };
                }
                return new ServiceResponse() { Success = true, Message = menuDatas.GetValue("message").ToString() };
            }
            catch (Exception ex)
            {
                return new ServiceResponse() { Success = false, ErrorCode = ex.Message, Message = ex.Message };
            }
            finally
            {
                httpClient0.Dispose();
            }
        }

JAVA接收wpf传入的json格式

  @ApiOperation("撤销")
    @PostMapping(value = "cancleMergBatch")
    public ResultBean cancleM(String revokeBatchParamStr) {
        try {
            RevokeBatchParam revokeBatchParamm = JSONArray.parseObject(revokeBatchParamStr,RevokeBatchParam.class);
            return manufOrdService.cancleMergBatch(revokeBatchParamm);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBean.failure("撤销更新失败");
        }
    }

WPF直接传对象【post】

   public async Task<ServiceResponse> GetBxPrintInfo(TBxManufPrintUptParam printUptParam)
        {
            HttpClient httpClient0 = new HttpClient();
            try
            {
                httpClient0.DefaultRequestHeaders.Add("Authorization", "Bearer " + this.token);
                var content = new StringContent(JsonConvert.SerializeObject(printUptParam), Encoding.UTF8, "application/json");
                Task<HttpResponseMessage> responseMessage = httpClient0.PostAsync(TQT.ServerBusiness.Properties.Resources.Http_Api + "services/servicepl/api/ipc/loose/getBxPrintInfo", content);
                responseMessage.Wait();
                Task<string> reString = responseMessage.Result.Content.ReadAsStringAsync();
                reString.Wait();
                Newtonsoft.Json.Linq.JObject menuDatas = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(reString.Result);
                //Newtonsoft.Json.Linq.JObject data = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(menuDatas.GetValue("data").ToString());
                Newtonsoft.Json.Linq.JArray data = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JArray>(menuDatas.GetValue("data").ToString());
                ServiceResponse response = new ServiceResponse() { Success = true, Results = data };
                return response;
            }
            catch (Exception ex)
            {
                LoggerHelper.WriteLog("获取打印数据失败", ex);
                return new ServiceResponse() { Success = false, ErrorCode = ex.Message, Message = ex.Message };
            }
            finally
            {
                //防止内存溢出
                httpClient0.Dispose();
            }

        }

java后台接收

 @ApiOperation("打印信息")
    @PostMapping(value = "getBxPrintInfo")
    public ResultBean getBxPrintInfo(@RequestBody TBxManufPrintUptParam printUptParam,HttpServletRequest request) {
        List<TBxManufLineEx> tBxManufLineExList = new ArrayList<>();
        tBxManufLineExList = bxManufPrintService.getBxPrintInfo(printUptParam,request);
        return ResultBean.success("获取并线打印信息成功!",tBxManufLineExList);
    }

二、参数个体传值【post】

wpf——>Java后台
单个参数传值格式【WPF】(post)

public async Task<ServiceResponse> Ol(string cntrCd, string entkbn, string pgmId, string userId, string userNm)
        {
            HttpClient httpClient0 = new HttpClient();
            try
            {
                httpClient0.DefaultRequestHeaders.Add("Authorization", "Bearer " + this.token);
                List<KeyValuePair<string, string>> param = new List<KeyValuePair<string, string>>();
                param.Add(new KeyValuePair<string, string>("cntrCd", cntrCd));
                param.Add(new KeyValuePair<string, string>("entkbn", entkbn));
                param.Add(new KeyValuePair<string, string>("pgmId", pgmId));
                param.Add(new KeyValuePair<string, string>("userId", userId));
                param.Add(new KeyValuePair<string, string>("userNm", userNm));
               // String path = TQT.ServerBusiness.Properties.Resources.Http_Api + "services/common/api/exclusive/openControl?" + param;
                Task<HttpResponseMessage> responseMessage = httpClient0.PostAsync(TQT.ServerBusiness.Properties.Resources.Http_Api + "services/common/api/exclusive/openControl", new FormUrlEncodedContent(param));
                responseMessage.Wait();
                Task<string> reString = responseMessage.Result.Content.ReadAsStringAsync();
                reString.Wait();
                Newtonsoft.Json.Linq.JObject menuDatas = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(reString.Result);
                var result = menuDatas.GetValue("success").ToString();
                if (result == "False")
                {
                    return new ServiceResponse() { Success = false, Message = menuDatas.GetValue("message").ToString() };
                }

                return new ServiceResponse() { Success = true, Message = menuDatas.GetValue("message").ToString() };
            }
            catch (Exception ex)
            {
                return new ServiceResponse() { Success = false, ErrorCode = ex.Message, Message = ex.Message };
            }
            finally
            {
                httpClient0.Dispose();
            }
        }

JAVA接收wpf传入的个体参数格式

    @ApiOperation("打开")
    @PostMapping(value = "ol")
    public ResultBean ol(HttpServletRequest request,String cntrCd,String entkbn,String pgmId,String userId,String userNm) {
        try {
            return mService.ol(request,cntrCd,entkbn,pgmId,userId,userNm);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBean.failure("打开更新失败");
        }
    }

三、个体传值[GET]

wpf——>Java后台
个体传值格式【WPF】(get)

 public async Task<ServiceResponse> getSameColorCd(string colorCd, string batchNo)
        {
            HttpClient httpClient0 = new HttpClient();
            try
            {
                string param = "colorCd=" + colorCd
                              +"&batchNo=" + batchNo;
                httpClient0.DefaultRequestHeaders.Add("Authorization", "Bearer " + this.token);
                String url = TQT.ServerBusiness.Properties.Resources.Http_Api + "services/servicepl/api/manufOrd/getSameColorCd?" + param;
                Task<HttpResponseMessage> responseMessage = httpClient0.GetAsync(url);
                responseMessage.Wait();
                Task<string> reString = responseMessage.Result.Content.ReadAsStringAsync();
                reString.Wait();
                Newtonsoft.Json.Linq.JObject menuDatas = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(reString.Result);
                //Newtonsoft.Json.Linq.JObject data = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(menuDatas.GetValue("data").ToString());
                ServiceResponse response = new ServiceResponse() { Success = true, Results = menuDatas };
                return response;
            }
            catch (Exception e) {
                LoggerHelper.WriteLog("根据色号查询异常", e);
                return new ServiceResponse() { Success = false, ErrorCode = e.Message, Message = e.Message };
            }
            finally
            {
                httpClient0.Dispose();
            }
        }

JAVA接收wpf传入的个体参数格式

    @ApiOperation("获取*****")
    @GetMapping(value = "getSrCd")
    public ResultBean getSaCd(String colorCd,String batchNo){
        List<TManufOrdEx> tManufOrds = new ArrayList<>();
        try {
            tManufOrds = manufOrdService.getSrCd(colorCd,batchNo);
            return ResultBean.success("获取******成功!",tManufOrds);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBean.failure("获取******失败!");
        }
    }

WPF传json对象,因字符串过长导致接口调用失败

wpf——>Java后台

 public async Task<ServiceResponse> SubmitExhaustCylinder(ExhaustCylinderParam exhaustCylinderParam)
        {
            HttpClient httpClient0 = new HttpClient();
            try
            {
                httpClient0.DefaultRequestHeaders.Add("Authorization", "Bearer " + this.token);
                Dictionary<String, Object> map = new Dictionary<String, Object>();
                map.Add("exhaustCylinderParamStr", exhaustCylinderParam);
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 
                timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss";
                String data = JsonConvert.SerializeObject(map, Formatting.Indented, timeConverter);
                var content = new StringContent(JsonConvert.SerializeObject(exhaustCylinderParam), Encoding.UTF8, "application/json");
                Task<HttpResponseMessage> responseMessage = httpClient0.PostAsync(TQT.ServerBusiness.Properties.Resources.Http_Api + "services/servicepl/api/exhaustCylinder/submitExhaustCylinder", content);
                responseMessage.Wait();
                Task<string> reString = responseMessage.Result.Content.ReadAsStringAsync();
                reString.Wait();
                Newtonsoft.Json.Linq.JObject menuDatas = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(reString.Result);
                var result = menuDatas.GetValue("success").ToString();
                if (result == "False")
                {
                    return new ServiceResponse() { Success = false, Message = menuDatas.GetValue("message").ToString() };
                }
                return new ServiceResponse() { Success = true, Message = menuDatas.GetValue("message").ToString() };
            }
            catch (Exception ex)
            {
                return new ServiceResponse() { Success = false, ErrorCode = ex.Message, Message = ex.Message };
            }
            finally
            {
                //防止内存溢出
                httpClient0.Dispose();
            }
        }

JAVA接收wpf传入的json对象格式

    @ApiOperation("提交调缸")
    @PostMapping(value = "submitExhaustCylinder")
    public ResultBean submitExhaustCylinder(HttpServletRequest request, @RequestBody ExhaustCylinderParam exhaustCylinderParam){
        try {
            if(exhaustCylinderParam == null){
                return ResultBean.failure("无提交数据!");
            }
            //返回区分  1:没有数据变更  2:数据修改过,没有重复数据   3:数据修改过,和当前页面有重复数据    4 数据修改过,与库中数据有重复数据
            int resultFlag = exhaustCylinderService.doubleCheckExhaustCylinder(exhaustCylinderParam);
            if(resultFlag == 1 ){
                return ResultBean.success("没有数据修改");
            }else if(resultFlag == 5){
                return ResultBean.failure("您的机台号没有对应的机台信息!");
            }
            return  ResultBean.success("提交成功!",exhaustCylinderService.doubleCheckExhaustCylinder(exhaustCylinderParam));
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBean.failure("提交失败");
        }
    }

WPF接收Java返回值

jarray类型转换成List对象

List<SameColorEx> data1 = req.Results.data.ToObject<List<SameColorEx>>();

接收map 并转换

/// <summary>
        /// 打印完成更新数据方法
        /// </summary>
        /// <param name="entity">领料单实体类</param>
        /// <returns>返回服务报文</returns>
        public async Task<ServiceResponse> prtLoosenBack(TWhPick entity, string loosenBackStockExs)
        {
            HttpClient httpClient0 = new HttpClient();
            try
            {
                List<KeyValuePair<string, string>> param = new List<KeyValuePair<string, string>>();
                param = HttpParamConverter.Convert(entity);
                param.Add(new KeyValuePair<string, string>("loosenBackStockExs", loosenBackStockExs));
                httpClient0.DefaultRequestHeaders.Add("Authorization", "Bearer " + this.token);
                String url = TQT.ServerBusiness.Properties.Resources.Http_Api + "services/servicepl/api/plan/prtLoosenBack";
                Task<HttpResponseMessage> responseMessage = httpClient0.PostAsync(url, new FormUrlEncodedContent(param));
                responseMessage.Wait();
                responseMessage.Wait();
                Task<string> reString = responseMessage.Result.Content.ReadAsStringAsync();
                reString.Wait();
                Newtonsoft.Json.Linq.JObject menuDatas = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(reString.Result);
                Newtonsoft.Json.Linq.JObject data = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(menuDatas.GetValue("data").ToString());
                ServiceResponse response = new ServiceResponse() { Success = true, Results = data };
                return response;
            }
            catch (Exception ex)
            {
                LoggerHelper.WriteLog("打印完成更新数据", ex);
                return new ServiceResponse() { Success = false, ErrorCode = ex.Message, Message = ex.Message };
            }
            finally
            {
                httpClient0.Dispose();
            }
        }


Dictionary<int, List<LoosenBackStockEx>> DetailStockBookDictionary = req.Results.data.looseDetail.ToObject<Dictionary<int, List<LoosenBackStockEx>>>();



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值