I need to generate in memory xml to pass to a web service method. VS did
not generate proxies for the objects that are needed for these web methods.
I'm spoiled, I've used many web services but never really needed to know how
to transmit the request as XML.
Here is the code I have to create the XML:
System.IO.StringWriter sw = new System.IO.StringWriter();
XmlTextWriter w = new XmlTextWriter(sw);
w.Formatting = Formatting.Indented;
w.WriteStartDocument();
w.WriteStartElement("RefundRequest");
w.WriteStartElement("AccountID");
w.WriteValue(ACCOUNT_ID);
w.WriteEndElement();
w.WriteStartElement("WebPassword");
w.WriteValue(ACCOUNT_PASSWORD);
w.WriteEndElement();
w.WriteStartElement("RefundList");
w.WriteStartElement("PICNumber");
w.WriteValue(trackingNumber);
w.WriteEndElement();
w.WriteEndElement();
w.WriteEndElement();
w.WriteEndDocument();
w.Close();
string requestXml = sw.ToString();
I have decorated the web methods in references.cs with the TraceExtension
attribute that will print the soap request/response to a log file.
Here is what the above XML is logged as:
----SoapRequest at 9/19/2008 10:40:19 PM
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="http://ELS" xmlns:types="http://ELS/encodedTypes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><tns:RefundRequest><XMLInput
xsi:type="xsd:string"><?xml version="1.0" encoding="utf-16"?>
<RefundRequest>
<AccountID>659995</AccountID>
<WebPassword>K!llerB00ts!</WebPassword>
<RefundList>
<PICNumber>9122148008600123456781</PICNumber>
</RefundList>
</RefundRequest></XMLInput></tns:RefundRequest></soap:Body></soap:Envelope>
I realize there are several problems here, but the first one I would like to
tackle is the '<' and '>' characters being replaced. I encountered this
when I first tried to write the XML to a string. I then googled and read a
bit about escaping XML and the suggestion was to do what I've done above.
However it seems that when I write the XML to the StringWriter it's
"unencoded" again or "unescaped" - remember, I don't know what I'm talking
about! ;0)
Can anyone clue me in on what I'm missing here? I'd love to spend days
learning about this (I would, really) but like most of you I'm in a time
crunch. I need a quick fix, I will research and learn why later.
Any help greatly appreciated,
Steve