webservice篇:其中关于调用外界数据,读取返回数据

1,通过Android中已存取的数据,返回数据(json格式,object类型数据:strJson)

2,业务需求:通过webservice调用外界暴露的数据并将返回来的json数据序列化,读取存入数据库表:【SQ_Event】

TODO:

1,讲解webservice小程序应用

2,json序列化

1,讲解webservice小程序应用

using HMFW.BLL.BaseInfo;using HMFW.BLL.SQJS.ZJWG;using HMFW.BLL.UserRoleManage;using HMFW.Common;using HMFW.Model;using System;using System.Collections.Generic;using System.Drawing;using System.IO;using System.Linq;using System.Web;using System.Web.Services;using System.Web.SessionState;namespace HMFW.Web.WebServiceToAndroid{/// <summary>/// Event 的摘要说明/// </summary>[WebService(Namespace = "")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][System.ComponentModel.ToolboxItem(false)]// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。// [System.Web.Script.Services.ScriptService]public class Event : System.Web.Services.WebService, IRequiresSessionState{private EventBLL iEventBll = new EventBLL();UsersBLL usersBll = new UsersBLL();sysAreaBLL sAreaBLL = new sysAreaBLL();/// <summary>/// 事件处理新增/// </summary>/// <param name="strJson"></param>/// <returns></returns>[WebMethod]public String AddEvent(string strJson){string resultJson = string.Empty; //返回结果变量AndrewsResultList resultList = new AndrewsResultList();//返回结果类SQ_Event model = null;try{model = JsonHelper<SQ_Event>.JsonStringToModel(strJson);model.gID = Guid.NewGuid();//获取数据录入人真实名称的信息sys_Users sys_UsersModel = new sys_Users();sys_UsersModel.gUserID = new Guid(model.gCreateUserId.ToString());sys_Users sys_UsersR = usersBll.GetModel(sys_UsersModel);model.sCreateUserRealname = sys_UsersR.sRealName;//获取所在地区名称的信息sysArea sysAreamodel = new sysArea();sysAreamodel.sID = model.sVillageCode;sysArea sysAreaR = sAreaBLL.GetModel(sysAreamodel);model.sVillageName = sysAreaR.sName;model.iDeleteMark = 0;model.iHandleState = 0;model.iState = 0;model.dCreateDate = DateTime.Now;/*************二进制流数据转换成图片******************/Bitmap bitmap;string[] arraysPicPath = model.sPicPath.Split(',');//arraysPicPath = sPicPath.Split(',');//测试数据流数组int spicLength = arraysPicPath.Length;//测试数据流长度string sImgPath = "";if (spicLength >= 2)//添加了图片{foreach (String item in arraysPicPath){if (!string.IsNullOrEmpty(item))//处理最后一个为空{#region 二进制流数据 生成图片//读取:二进制数据流图片生成图片string base64Decode = item;byte[] bt = Convert.FromBase64String(base64Decode);System.IO.MemoryStream stream = new System.IO.MemoryStream(bt);bitmap = new Bitmap(stream);//测试数据流数据生成图片#endregion#region 二进制流数据图片 保存进服务器指定路径//保存图片到指定路径下,采用原有保存格式,/upload/Android/20150107/c360f61b-8230-43d0-bae8-38d479cac802.JPGstring pathPrefix = "/upload/Android/";string path = Path.Combine(pathPrefix,DateTime.Now.ToString("yyyyMMdd") + "/" + Guid.NewGuid() + ".JPG");//合并2个路径字符串sImgPath += path + ',';//SQ_Event中sImgPath字段采取:逗号隔开方式进行保存多张图片[最多5张图片]string sbst;try{sbst = HttpContext.Current.Server.MapPath(path);}catch{sbst = path;}FileInfo fileInfo = new FileInfo(sbst);if (!fileInfo.Directory.Exists)fileInfo.Directory.Create();bitmap.Save(sbst);#endregion}}}if (!string.IsNullOrEmpty(sImgPath)){#region 第一时间中包含多张图片二进制数据流格式存储的图片以路径格式存储进服务器中sImgPath = sImgPath.Substring(0, sImgPath.Length – 1);//去除最后一个逗号model.sImgPath = sImgPath;//第一时间中包含多张图片二进制数据流格式存储的图片以路径格式存储进服务器中}#endregion}catch (Exception e)//如果解析出错,返回相关错误信息{resultList.sSuccess = "0";resultList.sMessage = "参数解析出错!" + e.Message;resultJson = JsonHelper<AndrewsResultList>.ModelToJsonString(resultList);return resultJson;}try{if (iEventBll.Add(model)){resultList.sSuccess = "1";resultList.sMessage = "执行成功!";resultJson = JsonHelper<AndrewsResultList>.ModelToJsonString(resultList);//对整个结果集进行序列化return resultJson;}else{resultList.sSuccess = "0";resultList.sMessage = "执行失败!";resultJson = JsonHelper<AndrewsResultList>.ModelToJsonString(resultList);//对整个结果集进行序列化return resultJson;}}catch (Exception e){resultList.sSuccess = "0";resultList.sMessage = "程序执行出错!" + e.Message;resultJson = JsonHelper<AndrewsResultList>.ModelToJsonString(resultList);return resultJson;}}}}2,json序列化

model = JsonHelper<SQ_Event>.JsonStringToModel(strJson);

TODO:

1,图片略,这主要是使用webservice调用外界数据的一个应用;

实际中,得来的数据都是已经保存入数据库中了。

2,没有什么图片看见了。

,德高培身,财多伤身。

webservice篇:其中关于调用外界数据,读取返回数据

相关文章:

你感兴趣的文章:

标签云: