本讲比较实际,在WEB端有一个Index和Create方法,用来从web api显示实体列表数据和向api插入实体对象,这就是以往的网站,只不过是把数据持久化过程放到了web pai上面,它的优势不用说,就是跨平台,跨语言,这其实是restFul的功功,一切通讯都变得那个简易,清晰!你再也不用引用程序集了...
先看一下实体的具体效果
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdkAAAFJCAIAAABYQ8AWAAAL4UlEQVR4nO3dQZLaSBaAYd1JOx9F245wX8E7ruAj6BTec4ZZehZDXYRZQIEylRICg19S+X3Ri6mSkGg73h/ZiaqmOwIQrYt+AwBoMUAFtBggnhYDxNNigHhaDBBPiwHiaTFAPC0GiKfFAPG0GCCeFgPE02KAeFoMEE+LAeIVWvz757du7tvP33//3QG0IWlxucJn339Fvcfj8df34DcA8FLXFv/6vtzhuBZP3pUWA1/WucX5ijjv3q/vWgzwMt3xmJe4quZpMdCC7pjtTtwsXlbHS8fTD/eyHY/iJ3+zXZHkrMU9k/QdbrkRQOW6dFW8IWXTFv8svXTxE8BJRJc/Jbxc5naLt9wI4B10afQ2VGypkaeIrj6KsSGj1xrfaPHGGwG8g+7eZXHWyOwVxa5P7vB5+u+f37JeFk7KLpicv/VGAO8gbfG96+LC4xalQ5NbrLyieNmFK95/I4CKZXsU9+0X52ev7xskiVx9mvlmi++4EcAbyD672xDjlafMtiayuC1SXtNqMdCC7piX7VaN15743fY08PV+t3eG79ujAHhPp5+7y3cMSpsPhd2FWQbXltjXH90r7XIsPeO8sDu97UYAb+Lz91Hc/q/+LS3etg98817ruxGno1s3nAHewPT3tK3/dqBtLV4t7eX8+Z2+/fxVfgZifrnPo1tuBPAWZr+/+OZvL960Vbu4nL2YbT4sP4+WXSw5evtGAPXz/+sBEE+LAeJpMUA8LQaIp8UA8bQYIJ4WA8TTYoB4WgwQT4sB4mkxQLxXtfgwDn3f97v9i64P8JV0l2z2w3h42mU/r7ktxvvd6eT8LZy//8w3BlCjF7X4vnXxpcXZm9BioBGvavFdJi1O3oYWA4241eIk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Klf7dVBXOX0n99wYKGjDsi2IzhllnjTjhWtBPHG9kneNtujM9eyqnRaV8pUDkPA2e1wH6d5u/oqSxLEuyvL1/4+m1qkpl0tqyO32Dxsvph0ouDSs6m5Kb/+eyzjCd4145T0O4ZLNkm3GzrrOtb1mWn/hp5ytT44Hq0STb60dmnUWCBfqV3j4KXlwv8MPJsZR1jqqqXGZbW2mnR6tME+0TymeyTjbGbJuxIevEezIrHq/xTHo661TqvNKrQJeiJ1bTke729ubB1iCLRAHlLVVlb05la3vvuk7jW0+XTKetlkltU8m1qdaFsfM0DkPxaeJ78+1lnXmUdd6rPZccknWu/zlP49rbfuYc6FQcNe4TX7gmc39SOCpYXYx5tapSmbS27E7f4N1ZJw03lQK1DW/3p24LN8GDxkEmzHWKrPM52ZOmPevclzXTkulb8RnzK6uiAB+2jnXDNAUP2STDX1hwzt7DOrCqQplMbbmdvsHhWae0VeWiPSxz/zITknZ/qXGmGXfvYZ39jYh3ack0D22bjThpgYcOEoDunaqeKPnc/yt7jI93/UH8i9d/QE3WeYtKWHl687duCECvKlNDmjweqqR+Zf764R1F1gEAeibrAAA9k3UAgJ7JOgBAz2QdAKBnP/8PAKBfsg4A0DNZBwDomawDAPRM1gEAeibrAAA9k3UAgJ7JOgBAz2QdAKBnsg4A0DNZBwDomawDAPRM1gEAeibrAAA9k3UAgJ7JOgBAz2QdAKBnsg4A0DNZBwDomawDAPRM1gEAeibrAAA9k3UAgJ7JOgBAz2QdAKBnsg4A0DNZBwDomawDAPRM1gEAeibrAAA9k3UAgJ7JOgBAz2QdAKBnsg4A0DNZBwDomawDAPRM1gEAeibrAAA9k3UAgJ7JOgBAz/4/lsPskm/dJzIAAAAASUVORK5CYII=" alt="" />
我们看到如图,它们在取数据和插数据的时间,走的都是restful标准,都是通过web api实现的,当然,对于通讯来说,要求你的实体必须是可序列化的,这是正常的,而且对于EF来说,很容易办这事,只要修改T4模版就可以搞定。
看一下具体web api代码,采用unity实现的注入,后台BLL层使用了cache机制,可以实现EntLib和redis两种方式进行持久化,可以通过配置文件实现切换,对于数据持久化方式,实现了ef和redis的动态切换
Api代码
/// <summary>
/// 用户业务接口
/// </summary>
public class UserController : ApiController
{
IUserService userService; public UserController()
{
userService = ServiceLocator.Instance.GetService<IUserService>();
}
// GET api/user
public IEnumerable<WebManageUsers> Get()
{
return userService.GetWebManageUsers(new PageParameters(, ));
} // GET api/user/5
public WebManageUsers Get(int id)
{
return userService.GetWebManageUser(i => i.ManageUserID == id);
} // POST api/user
public void Post([FromBody]WebManageUsers value)
{
userService.InsertManageUsers(value);
} // PUT api/user/5
public void Put(int id, [FromBody]WebManageUsers value)
{
var entity = userService.GetWebManageUser(i => i.ManageUserID == id);
if (entity != null)
{
entity = value.MapTo<WebManageUsers>();
userService.ModifyManageUsers(entity);
}
} // DELETE api/user/5
public void Delete(int id)
{
userService.DeleteManageUsers(new WebManageUsers { ManageUserID = id });
}
}
Client端代码,使用HttpClient实现异步通讯
public class HomeController : Controller
{
private HttpClient client = new HttpClient();
private string url = "http://localhost:52824/api/user";
private JsonMediaTypeFormatter formatter = System.Web.Http.GlobalConfiguration.Configuration.Formatters.Where(f =>
{
return f.SupportedMediaTypes.Any(v => v.MediaType.Equals("application/json", StringComparison.CurrentCultureIgnoreCase));
}).FirstOrDefault() as JsonMediaTypeFormatter; public async Task<ActionResult> Index()
{
var data = await client.GetAsync(url);
return View(data.Content.ReadAsAsync<IEnumerable<WebManageUsers>>());
} public ActionResult Create()
{
return View();
}
[HttpPost]
public async Task<ActionResult> Create(WebManageUsers entity)
{
entity.Password = string.Empty;
entity.Status = ;
entity.CreateDate = DateTime.Now;
entity.UpdateDate = DateTime.Now;
entity.Description = string.Empty;
entity.Operator = string.Empty;
entity.RealName = string.Empty;
entity.WebSystemID = ;
entity.DepartmentID = ;
var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip };
using (var http = new HttpClient(handler))
{
var response = await http.PostAsync<WebManageUsers>(url, entity, formatter);
return RedirectToAction("Index");
}
}
}
我们通过上面的例子可以看到,在client端与api进行通讯时,使用了实体类型,并没有进行JSON拼串,这是友好的,事实上,这个过程是.net为我们实现了,当然你要首先指定它的JSON持久化功能代码,如图
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA1YAAABQCAIAAACVj3O8AAAVKElEQVR4nO2dTXLkqhKFWRbrYSUeM/ciPGIFvYaO0BLuHojncNjhN0BAJmQipPpvnS867i1TEiSQwFEilUwEAAAAAAAnwzzaAAAAAAAAcG8gAQEAAAAATsftJeDyZc13uHkxSuHemoq7zIzgjDHWl7+9ZX8OTyNFL95uWcLNNsZYvxy3mxnCc70808dDGusqzfQy1Ipbax9e9exd1rM/JKsmBw7J1QXy6VbU9nTeu2R5rshGsTtqpOZZhqf13h3pTnEgTMw2N+T6paOVNvlH53mGPNtYe/MZgrncP7H0PHcUcPmy7vMK+YRDk4WYj7Wri9HPW/jZA1eW9YTgVhe/koMt1JA185uwSDUWE29T1PW5Y40mqdPR4u2BKejqxjduumQZpRy6O1dq8PW7I7jShsE1U/pEvrtHE88zuLJ2LUlP7h7wj3TGO5WNVjpQ0D8yz7cos80tyw6O68vjFT02Y9+G3RLQ219jv4L7NebXmN/cBJ/O/Brz48OXNb8mh/3yYSUKmA77Nfar+XbxP4Z8FWOM4XtNSf+yFqxHmp/ZRqTuQq71q4QjAZV0YJphrOUSPzjrXDrJ2/JRuRgoF2Mu+KobhQAALby3m/5Vj8mf00RIiurypCatPsuz7epecw/pqxqDydVpGoob31yFJpvERNnOvnQVFi0tBrxyjebxfeRP8hBuU/b5WePVVhJYR1nWUnnQyQ1ifUkfN4cgAae7Qxsdw2LEpuanig4m1Ugf2jxPrfTJeUkZCHK4sQZQfNqfqNsU1GcUp50dHVrp0zUSQCvNtFJ88XleXKB7lNnGW+e6LYj50kdxPa4A5aVnnlTS4yIIhQNRwE9XBdmnIzosuCzLwrf1/ysneMs2gumf9XP4zH3wU8/to4DLly0akX4eQ+aO+rFeUpIAAInJs+/zB+sXb12o/1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H6vBGzz7CXg4JYycTnuj7uKBBTufZtr5BoFNL9FAsbwXRIn98Ub6dS2vBxqbRu7JmXRVWR238hLGyMdSUCx5Vm5vXG1AJ55cNYvar/3TqvUvfumfkf2qJsw89C9pMSBf97xflEAAAAvzPEngoVb8/dJQIEpCUjzoYGQzpjZFVrcCNYLbouiDUHOeqQEXL5sCfKF7yoB6QF0g7j9dthYkbT8XgmYI19EULWZ75CASsuzctm5jcRsN4tH/X6Jg4kSUDN+Mgqo+yckIAAAgBluvhGcwhWtZjouAUkZ8l5Y2YRUHwcZS0CySyhbKUjA/Pe607d+Xj/2T78KErA1vtb2yEbw8mXdZy6rRAE/XdGFYwlIimU6RWh55gYkvKZKwJJB7iPJY0hnjDaClZbvDSNp3rGdXMMMHfS7+LyRVPeurroEFI0XnUF2b9kPRAlYd4cBAACAGOPVHwcR4xdcAor7uM0d7/muLGGjix3ZqKVuQ7BLE/PUHsgQiuKHsoc/jMkPQTTPL1jv8z1nUjVV4+U2nb0V0OVdYPuTt30/Xd4F3tgIpg2l9FFJ7nczc4qrT0KUh0OKNi+HS7lSF7GrgJabTmx5emhTTa4Ug0sPhezq9yYK2RgkONh6rvXLejGQd8Nlt1GcQUjs7ZSHTGzELgAAABAf86MwYAeP/lGYfwseyrvlb7s8FZN3aAAAADgT9/9paLCP5UE/Df1vIYTx6i/cQFMDAAA4H3hBHAAAAADA6YAEBAAAAAA4HZCAAAAAAACnAxIQAAAAAOB0QAICAAAAAJwOSEAAAAAAgNMBCQgAAAAAcDogAQEAAAAATgckIAAAAADA6YAEBAAAAAA4HZCAAAAAAACnAxIQAAAAAOB0QAICAAAAAJyO/wNWTbvezaRUPAAAAABJRU5ErkJggg==" alt="" />
好了,对于基于实体的Web api通讯就说到这里了,感谢阅读!