I need to call a WCF endpoint using an HTTPClient which I have already figured out how to do that. The problem that I have is that I do not know how to code the XML serializer to produce the content string that has worked.
In my code I have the following type:
public class MyParameters
{
public string source { get; set; }
public string key { get; set; }
public string secret { get; set; }
public TimeSpan lockExpirationTime { get; set; }
}
And I serialize it like so:
var input = new MyParameters
{
source = "some source",
key = "some key",
secret = "some secret",
lockExpirationTime = new TimeSpan(0, 0, 10)
};
var serializer = new XmlSerializer(typeof(MyParameters));
var stringwriter = new System.IO.StringWriter();
serializer.Serialize(stringwriter, input);
var xml = stringwriter.ToString();
The end result is this xml string:
<?xml version="1.0" encoding="utf-16"?>
<MyParameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<source>some source</source>
<key>some key</key>
<secret>some secret</secret>
<lockExpirationTime>PT10S</lockExpirationTime>
</MyParameters>
But it seems that for the WCF endpoint to be happy and not return a Bad Request result the xml needs to look EXACTLY like this:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<MyParameters xmlns="http://tempuri.org/">
<source>some source</source>
<key>some key</key>
<secret>some secret</secret>
<lockExpirationTime>PT10S</lockExpirationTime>
</MyParameters>
</s:Body>
</s:Envelope>
How can I make the serializer give me this result? I am using .Net Core 3.1
Thank you.