服务返回JSON格式数据

以WCF服务为例

方法调用

string jsonresult = MyBaseManageProxy.SaveStorage(MySe, UserID);

Contract

 [OperationContract]
        [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string SaveStorage(StorageEntity se, string userId);

Service

  public string SaveStorage(StorageEntity se, string userId)
        {
            return JsonConvert.SerializeObject(MyBaseBLL.SaveStorage(se, userId));
        }
    }
}

BILL

  public FeedbackInfomation SaveStorage(StorageEntity se, string userId)
        {
            FeedbackInfomation fi = new FeedbackInfomation();
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    if (se.StorageID == null || se.StorageID == "")
                    {
                        se = MyBaseDAL.InsertStorageEntity(se);
                      //  LogEntity le = this.GenerateLog("基础维护", "仓库维护", "新增", DateTime.Now, userId, "");
                       // le = MyBaseDAL.InsertLogEntity(le);
                        //LogDetailEntity lde = this.GenerateLogDetail(le.LogID, "Com_StorageRoom", se.StorageID, "");
                       // lde = MyBaseDAL.InsertLogDetailEntity(lde);


                    }
                    else
                    {
                        se = MyBaseDAL.UpdateStorageEntity(se);
                        //LogEntity le = this.GenerateLog("基础维护", "仓库维护", "修改", DateTime.Now, userId, "");
                        //le = MyBaseDAL.InsertLogEntity(le);
                        //LogDetailEntity lde = this.GenerateLogDetail(le.LogID, "Com_StorageRoom", se.StorageID, "");
                        //lde = MyBaseDAL.InsertLogDetailEntity(lde);
                    }
                    scope.Complete();
                }
                fi.ErrorStatus = STATUS_ADAPTER.SAVE_SUCCESS;
                fi.Result = se;
                fi.FeedbackMessage = Tips.SAVE_SUCCESS;
                return fi;
            }
            catch (Exception ex)
            {
                fi.ErrorStatus = STATUS_ADAPTER.SAVE_FAILED;
                fi.Result = "";
                fi.FeedbackMessage = Tips.SAVE_FAILED;
                return fi;
            }
        }

FeedbackInfomation

namespace CMST.Storage.Server.Common
{
    [DataContract]
    public class FeedbackInfomation
    {
        [DataMember]
        public object Result { get; set; }

        [DataMember]
        public STATUS_ADAPTER ErrorStatus { get; set; }

        [DataMember]
        public string FeedbackMessage { get; set; }
    }
}

解析JOSN为LIST

 FeedbackInfomation fi = JsonConvert.DeserializeObject<FeedbackInfomation>(jsonresult);
            if(fi.ErrorStatus == STATUS_ADAPTER.QUERY_NORMAL)
            {
                MySes = JsonConvert.DeserializeObject<List<StorageEntity>>(fi.Result.ToString());
                this.View.SetDataSource(MySes);
            }
            else
            {
                this.View.ShowTips(fi.FeedbackMessage);
            }
  public void SetDataSource(List<StorageEntity> ses)
        {
            this.dgvStorageInfo.DataSource = new List<StorageEntity>();
            this.dgvStorageInfo.DataSource = ses;
        }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,246评论 19 139
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,834评论 18 399
  • 氧气 抱着你哭 月光 糖罐子
    cheerhoo阅读 114评论 0 0
  • 公司年终总结工作内容写得比较详细,这里就简要总结下,公司那份最后就放点出来。 简要总结 2013年春节前,在佳音实...
    roowe阅读 334评论 0 0