WCF REST: What is it expecting my XML to look like in requests?

前端 未结 2 1342
旧时难觅i
旧时难觅i 2021-02-09 16:18

I have the following method in my WCF service:

[OperationContract]
[WebInvoke(Method = \"POST\", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessag         


        
2条回答
  •  误落风尘
    2021-02-09 16:25

    Valid XML must have a single root element. Also there's no magic in WCF REST that maps XML elements to string parameters. You could take an XElement as your operation parameter.

    [OperationContract]
    [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)]
    public int GetOne(XElement content)
    {
        string param1 = content.Elements().First(element => element.Name == "param1").Value;
        string param2 = content.Elements().First(element => element.Name == "param2").Value;
    
        return 1;
    }
    

    The data you send would be something like:

    
        something
        something
    
    

提交回复
热议问题