473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

writing XML to string to pass to web method

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">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;RefundRequest&gt;
&lt;AccountID&gt;659995&lt;/AccountID&gt;
&lt;WebPassword&gt;K!llerB00ts!&lt;/WebPassword&gt;
&lt;RefundList&gt;
&lt;PICNumber&gt;9122148008600123456781&lt;/PICNumber&gt;
&lt;/RefundList&gt;
&lt;/RefundRequest&gt;</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
Sep 20 '08 #1
0 1061

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it...
10
by: cppdev | last post by:
Hi All! I want to clear the string contents from sensitive information such as passwords, and etc. It's always a case that password will appear as string at some point or another. And i feel...
8
by: A.M | last post by:
Hi, Are string parameters in functions by refrence or by value ? Thanks, Ali
4
by: JP | last post by:
Okay - I have incorporated some of the advise I got on the first post and have gone ahead and setup a simple test project to demonstrate the trouble I am having. Any help is GREATLY appreciated: ...
5
by: RD | last post by:
Form1 calls a sub that is public in module1. How do you write a value to a text property from with this sub? Eg Module myModule sub mysub() 'From here how do I write to the label1.text...
6
by: Adam Honek | last post by:
Can anyone spot why the below function is failing? It returns true but when looking inside the INI file there's no new added section. ****CODE**** Public Function WriteINIFileSection(ByVal...
10
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.