I am trying to post some XML data with RestSharp. The web service API that I am posting to expects XML data that has the following structure:

<?xml version="1.0"?>
<rootElement>
   <first-child></first-child>
   <second-child></second-child>
<rootElement/>

I also have a class that I want to serialize to the required XML and which I will attach to the post request via request.AddObject(). Here is my class:

public class MyRootElement
{
    public string firstchild { get; set; }
    public string secondchild { get; set; }
}

Now, here is my problem: How do I get RestSharp to serialize my class so that the dashes are inserted into the names of the XML elements? Currently, the web service API I am posting to is refusing the request because it doesn't recognize the XML I am posting.

有帮助吗?

解决方案

Write an ISerializer implementation that does what you want (probably working with .NET's XmlSerializer), and register it with RestClient.XmlSerializer = new YourSerializer();

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top