private MiddleResult GetMiddleResult(HttpResponseMessage httpResponseMessage) { // 3、将HttpResponseMessage转换成MiddleResult if (httpResponseMessage.StatusCode.Equals(HttpStatusCode.OK) || httpResponseMessage.StatusCode.Equals(HttpStatusCode.Created) || httpResponseMessage.StatusCode.Equals(HttpStatusCode.Accepted)) { string httpJsonString = httpResponseMessage.Content.ReadAsStringAsync().Result; // 3.1 创建MiddleResult return(MiddleResult.JsonToMiddleResult(httpJsonString)); } if (httpResponseMessage.StatusCode.Equals(HttpStatusCode.NotFound)) { string httpJsonString = httpResponseMessage.Content.ReadAsStringAsync().Result; // 3.1 创建MiddleResult return(MiddleResult.JsonToMiddleResult(httpJsonString)); } else { throw new FrameException($"{HttpConst}服务调用错误:{httpResponseMessage.Content.ReadAsStringAsync().ToString()}"); } }
/// <summary> /// 中台结果串转换成为MiddleResult /// </summary> /// <param name="jsonStr"></param> /// <returns></returns> public static MiddleResult JsonToMiddleResult(string jsonStr) { MiddleResult result = JsonConvert.DeserializeObject <MiddleResult>(jsonStr); return(result); }
public MiddleResult(string jsonStr) { MiddleResult result = JsonConvert.DeserializeObject <MiddleResult>(jsonStr); }