Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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
Asp.net WCF REST如何能够同时接受XML和JSON作为请求?_Asp.net_Json_Wcf_Service_Wcf Rest - Fatal编程技术网

Asp.net WCF REST如何能够同时接受XML和JSON作为请求?

Asp.net WCF REST如何能够同时接受XML和JSON作为请求?,asp.net,json,wcf,service,wcf-rest,Asp.net,Json,Wcf,Service,Wcf Rest,我已经创建了WCF REST服务,它接受RequestFormat为JSON和BodyStyle=Wrapped。如果消费者(.NET、JAVA、PHP、JAVASCRIPT e.t.c.)发布了复杂的(类对象)数据,我想让我的服务接受XML。我已在web.config中将属性(AutomaticFormatSelectEnabled)启用为true。我有以下几个问题 我们可以让REST服务接受XML或JSON/这两种格式作为请求吗 BodyStyle在接受两种格式时是否有所不同 我们如何将复杂

我已经创建了WCF REST服务,它接受RequestFormat为JSONBodyStyle=Wrapped。如果消费者(.NET、JAVA、PHP、JAVASCRIPT e.t.c.)发布了复杂的(类对象)数据,我想让我的服务接受XML。我已在web.config中将属性(AutomaticFormatSelectEnabled)启用为true。我有以下几个问题

  • 我们可以让REST服务接受XML或JSON/这两种格式作为请求吗
  • BodyStyle在接受两种格式时是否有所不同
  • 我们如何将复杂对象发送到JSON或XML/这两种格式的后期合约
  • 创建所有平台都可以使用的REST服务时,需要采取哪些预防措施

  • 假设控制器操作具有相同的签名,则可以将JSON设置为
    GET
    ,将XML设置为
    POST

    [HttpPost]
    public ActionResult Test(string xml)
    {
      ...
    }
    
    [HttpGet]
    public ActionResult Test(string json)
    {
      ...
    }
    

    至于POST,您可能需要有一个专门的操作来发布XML或JSON

    POST方法的输入参数是string吗?复合数据类型或内置数据类型。。