I'm trying to figure out how to properly serialize my XmlDocument and send it via a HTTPWebRequest object.
Heres what I have thusfar:
Stream requestStream;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://wwwcie.ups.com/ups.app/xml/Track");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
requestStream = request.GetRequestStream();
XmlSerializerNamespaces xsm = new XmlSerializerNamespaces();
xsm.Add("", ""); // remove namespace
XmlSerializer ser = new XmlSerializer(xmlRequest.GetType());
ser.Serialize(requestStream, xmlRequest);
requestStream.Write(postData, 0, postData.Length);
requestStream.Close();
A few things I'm uncertain about. I have 2 XmlDocuments I need to send in the same HTTPWebRequest. I've tried before to convert the XmlDocuments to strings and just concatenate them (to send the string) but when I used the StringBuilder / Writer it adds:
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://myNameSpace/">
I already have the declaration in my XmlDocument objects so now its in there twice, and I cannot have the <string...
part in there. Is it easier to convert the XmlDocuments to strings then concatenate them and send that or is there a easy way to send the XmlDocuments as they are?
Edit:
See http://stackoverflow.com/questions/1104549/c-xmldocument-nodes When I try to convert one of my XmlDocuments to a string it shows up as
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://myNamespace/">
<TrackRequest>
<Request>
<TransactionReference>
<CustomerContext>whatever</CustomerContext>
</TransactionReference>
</Request>
<TrackingNumber>123</TrackingNumber>
</TrackRequest>
</string>
I want my root to be <TrackRequest>