How to manually create a SOAP envelope in C #?

I am trying to manually create a SOAP envelope in C #. First, I took the path of creating it through StringBuilder and added it to the XmlDocument using the LoadXml method. However, after execution, I get an exception on the lines:

System.Xml.XmlException: character ':', hexadecimal value 0x3A, cannot be included in the name. Line 1, position 200.

The envelope I'm trying to create is:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XmlSchema"> <soap:Header> <wsrp:path soap:actor="http://schemas.xmlsoap.org/soap/actor/next" soap:mustUnderstand="1" xmlns:wsrp="http://schemas.xmlsoap.org/rp"> <wsrp:action> http://abcd.com/Webservices </wsrp:action> <wsrp:to> http://abcd.com/Webservices.asmx </wsrp:to> <wsrp:id> uuid:aaaaa0a7-9e46-432b-8f1b-35037077601f </wsrp:id> </wsrp:path> <wsu:Timestamp xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility"> <wsu:Created> 2012-11-30T10:38:13z </wsu:Created> <wsu:Expires> 2012-11-30T11:38:13z </wsu:Expires> </wsu:Timestamp> <wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext"> <wsse:UsernameToken wsu:Id="SecurityToken-00c26e1a-3b3b-400f-a99a-3aa54cf8c8ff" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility"> <wsse:Username>username</wsse:Username> <wsse:Password Type="wsse:PasswordText">password</wsse:Password> <wsse:Nonce>NBzqolcwIZrAOYw1vLyucDM3sQQ=</wsse:Nonce> <wsu:Created>2012-11-30T10:38:13z</wsu:Created> </wsse:UsernameToken> </wsse:Security> </soap:Header> <soap:Body> <MethodName xmlns="http://abcd.com/Webservices"> <ValueField>Ford</ValueField> </MethodName> </soap:Body> </soap:Envelope> 

I am trying to understand why the compiler is not happy with the ":". Is there a better way to do this / what am I doing wrong here?

+4
source share
1 answer

Thanks for the input. FYI, the solution that worked for me, was to prefix the string with the @ symbol, and instead of using the "escape sequence for double quotes, I went for" (i.e. two sets of double quotes, where an escape sequence is required) - works with pleasure.

0
source

All Articles