当前位置: 代码迷 >> Web Service >> WCF 怎么接受处理POST过来的数据
  详细解决方案

WCF 怎么接受处理POST过来的数据

热度:129   发布时间:2012-11-17 11:14:16.0
WCF 如何接受处理POST过来的数据
1.在接口IService.cs中定义: 
[OperationContract]
  [WebInvoke(Method="POST", UriTemplate="/admin/post")]
  void CreatePost(Message ms);(Message是个对象)
2. 在Service.cs中实现
  public void CreatePost(Message ms)
  {

  } 
3. 在宿主程序中
  WebServiceHost host = new WebServiceHost(service, new Uri("http://localhost:8000/blog"));
  host.AddServiceEndpoint(typeof(BlogService.IBlogService), binding, "");
  host.Open();
  var client = new WebClient();
  client.Headers.Add("content-type", "application/x-www-form-urlencoded");
  var s1 = client.UploadString("http://localhost:8000/blog/admin/post", "POST", ms);
请教:
  1.WCF在什么地方接受client POST过去的数据,是如何处理的?
  2.客户端在POST给WCF需要按照什么特定的格式么?如果有,是什么样的?
望各位大虾赐教!

------解决方案--------------------
1 所有的消息都是通过Channel传输 通过 channel dispatch 到相应的 endpoint.
2 消息的格式那要看你server 的 message contract

  相关解决方案