2013-07-18 24 views
1

好吧,让我说我想用POSTMAN或任何其他Rest服务客户端工具来调用我的代码,我该怎么做呢?我的一个参数“数据”是巨大的,我不要想在URL中包含“数据”或有效载荷,我想从身体调用它?如何使用POSTMAN或任何客户端工具应用程序调用RestFul WCF POST服务?

下面是实际的代码

[OperationContract(Name = "createNewSurvey")] 
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "post/createNewSurvey")] 
    string CreateNewSurvey(string id, string Data); 


public string CreateNewSurvey(string id, [FromBody]string Data) 
    { 
     //do somethoinf 
     return data; 
    } 

任何帮助,将不胜感激它

感谢

回答

0

安装一个叫Fiddler工具,然后使用下面的原始请求。

URL:http://localhost/Sample/Service1.svc/post/createNewSurvey 
User-Agent: Fiddler 
Content-Type: application/json 
Host: localhost 

{"id":"5","Data":"sample data to be sent to server"} 
+0

为什么没有邮递员? –

5

在邮差你必须写这个字符串http://localhost/Sample/Service1.svc/createNewSurvey在框“中输入请求的URL”,并选择了POST,添加在标题中这两个键:

  • 内容类型:应用程序/ JSON
  • 主机:本地主机

,并在身体中选择 “原始” 单选按钮,并写上:

  • { “ID”: “5”, “数据”: “样本数据被发送到服务器”}

see the image like example

相关问题