服務返回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閱讀 134,915評論 18 139
  • 1. Java基礎部分 基礎部分的順序:基本語法,類相關的語法,內部類的語法,繼承相關的語法,異常的語法,線程的語...
    子非魚_t_閱讀 31,765評論 18 399
  • 氧氣 抱著你哭 月光 糖罐子
    cheerhoo閱讀 111評論 0 0
  • 公司年終總結工作內容寫得比較詳細,這里就簡要總結下,公司那份最后就放點出來。 簡要總結 2013年春節前,在佳音實...
    roowe閱讀 331評論 0 0