[转]WCF RESTful service and WebGrid in ASP.NET MVC 5

时间:2023-03-09 16:16:22
[转]WCF RESTful service and WebGrid in ASP.NET MVC 5

使用WebClient调用WCF服务

流程:从View获取实体类-->序列化-->写入内存流中-->传给远端的WCF服务

Get、POST、PUT、DELETE,客户端以流的方式调用服务:

 var request = new GetListRequest
{
UserStateId = ""
}; using (WebClient wc = new WebClient())
{
MemoryStream ms = new MemoryStream();
DataContractJsonSerializer serializerToUplaod = new DataContractJsonSerializer(typeof(GetReceiptListRequest));
serializerToUplaod.WriteObject(ms, request);
wc.Headers["Content-type"] = "application/json";
var rstStream = wc.UploadData("http://localhost:333/Account/GetList", "POST", ms.ToArray()); string rstStr = Encoding.UTF8.GetString(rstStream).UrlDecoding();
}

http://www.codeproject.com/Articles/788580/WCF-RESTful-service-and-WebGrid-in-ASP-NET-MVC-P

http://www.codeproject.com/Articles/788583/WCF-RESTful-service-and-WebGrid-in-ASP-NET-MVC-Par

http://www.codeproject.com/Articles/35982/REST-WCF-and-Streams-Getting-Rid-of-those-Names-Sp