服务端:

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);
}

posted on 2015-02-10 16:49  fuyujian  阅读(316)  评论(0编辑  收藏  举报