Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将JSON HTTP请求发布到WCF制作的RESTful API_C#_Json_Wcf_Rest_Request - Fatal编程技术网

C# 如何将JSON HTTP请求发布到WCF制作的RESTful API

C# 如何将JSON HTTP请求发布到WCF制作的RESTful API,c#,json,wcf,rest,request,C#,Json,Wcf,Rest,Request,我试图让Android使用我自己制作的一个简单的WCF Web服务。以下是我的WCF服务定义: [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/UploadCallLog2")] [Op

我试图让Android使用我自己制作的一个简单的WCF Web服务。以下是我的WCF服务定义:

    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json,
    RequestFormat = WebMessageFormat.Json,
    BodyStyle = WebMessageBodyStyle.Bare,
    UriTemplate = "/UploadCallLog2")]
    [OperationContract]
    String UploadCallLog2(String number, String cached_name, String duration, String date, String line_number);
我有两个问题: 1.我的HTTP请求应该是什么样子?添加请求头时,我应该选择哪种内容类型? 2.是否有正确的方法将输入参数作为JSON放在主体中,Web服务可以自动检测输入参数的值


Fred

我建议通过WCF服务使用MVC项目

控制器可以返回一个JsonResult,MVC库包含Json助手方法,如果属性匹配,可以将Json对象序列化和反序列化为c#对象

此外,这还允许从任何支持使用ContentType作为“application/json”的XmlHttpRequest的客户端调用基于MVC的服务。您可以使用HttpGet或HttpPost,这取决于您的请求类型以及SSL下数据的安全性。您还可以利用身份验证模型来保护您的方法

这使得实现非常干净,没有任何复杂的服务器和客户端配置。有关类似方法的更多信息,请参阅MVC4中的新Web API