码迷,mamicode.com
首页 > 其他好文 > 详细

wcf post

时间:2015-02-10 18:24:02      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:

服务端:

1、接口

[OperationContract]
[ServiceKnownType(typeof(CreatMicroBlogFeedViewModel))]
[WebInvoke(BodyStyle=WebMessageBodyStyle.Wrapped,Method="POST",RequestFormat=WebMessageFormat.Json)]
int AppCreatMicroBlogFeed1(CreatMicroBlogFeedViewModel model);

2、实现

public int AppCreatMicroBlogFeed1(CreatMicroBlogFeedViewModel model)
{
if (model != null)
{
var micromodel = new MicroblogViewModel();
micromodel.BlogID = model.blogid;
micromodel.SenderID = model.senderid;
micromodel.SenderName = model.sendername;
micromodel.Body = model.body;
micromodel.MroblogPic = model.pic;
micromodel.VisitRole = (AccessPower)model.power;
micromodel.IsShare = model.shareid > 0;
if (model.shareid > 0)
{
micromodel.ShareID = model.shareid;
}
return Getter.GetByName<IAddFeedHelper<MicroblogViewModel>>("MicroBlog").Add(micromodel);
}
return 0;
}

3、客户端获取

public int CreateFeed(int blogid, int senderid, string sendername, string body, string pic, int power, int shareid = 0)
{
var requestJson = JsonConvert.SerializeObject(new { blogid, senderid, sendername=HttpUtility.UrlEncode(sendername), body=HttpUtility.UrlEncode(body), pic=HttpUtility.UrlEncode(pic), power, shareid});
HttpContent httpContent = new StringContent(requestJson);
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var url = THZConfigHelper<AppConfig>.Instance.THZServicesConfig.CreatFeed;
var str = feedclient.PostAsync(url, httpContent).Result.Content.ReadAsStringAsync().Result;
return int.Parse(str);
}

wcf post

标签:

原文地址:http://www.cnblogs.com/fuyujian/p/4284327.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!