Passing HTML tags in a SOAP call

Posted on 2006-05-11
Medium Priority
Last Modified: 2008-02-01
Hey guys,

I am trying to pass an email body which has some HTML tags (<br><a><b>etc..) in a SOAP call.  The SOAP calls looks like this:

strXML = "<?xml version=""1.0"" encoding=""utf-8""?>" & _
            "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
                  "<soap:Body>" & _
                  "      <SendEmail xmlns=""some uri"">" & _
                  "            <CallingApplication>" & CallingApplication & "</CallingApplication>" & _
                  "            <MESSAGE>" & _
                  "                  <MESSAGE_ADDRESS_TO>" & MESSAGE_ADDRESS_TO & "</MESSAGE_ADDRESS_TO>" & _
                  "                  <MESSAGE_ADDRESS_FROM>" & MESSAGE_ADDRESS_FROM & "</MESSAGE_ADDRESS_FROM>" & _
                  "                  <MESSAGE_ADDRESS_CC>" & MESSAGE_ADDRESS_CC & "</MESSAGE_ADDRESS_CC>" & _
                  "                  <MESSAGE_ADDRESS_BCC>" & MESSAGE_ADDRESS_BCC & "</MESSAGE_ADDRESS_BCC>" & _
                  "                  <MESSAGE_BODY>" & MESSAGE_BODY & "</MESSAGE_BODY>" & _
                  "                  <MESSAGE_SUBJECT>" & MESSAGE_SUBJECT & "</MESSAGE_SUBJECT>" & _
                  "                  <MESSAGE_BODY_IS_HTML>" & MESSAGE_BODY_IS_HTML & "</MESSAGE_BODY_IS_HTML>" & _
                  "            </MESSAGE>" & _
                  "      </SendEmail>" & _
                  "</soap:Body>" & _
      dim xmlDoc, strResponse
      set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
      dim xmlhttp
      set xmlhttp = Server.Createobject("Microsoft.XMLHTTP")
      xmlhttp.open "POST", "http://axios/sendmail/sendmail.asmx", false
      xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
      xmlhttp.setRequestHeader "SOAPAction", "some method"      
      xmlhttp.send xmlDoc

This fails on .send if my MESSAGE_BODY parameter contains any HTML tags.  If MESSAGE_BODY  does not have any HTML tags then it works fine.

The error message I get is:

<?xml version="1.0" encoding="utf-8" ?>
- <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:Body>
- <soap:Fault>
  <faultstring>System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (1, 583). ---> System.Xml.XmlException: 'Text' is an invalid node type. Line 1, position 583. at System.Xml.XmlReader.ReadElementString() at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read3_Email(Boolean isNullable, Boolean checkType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read10_SendEmail() --- End of inner exception stack trace --- at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle) at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader) at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters() --- End of inner exception stack trace --- at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters() at System.Web.Services.Protocols.WebServiceHandler.Invoke() at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()</faultstring>
  <detail />

Any ideas?

Question by:Leo Eikelman
  • 3
LVL 31

Accepted Solution

alorentz earned 2000 total points
ID: 16662756
probably need to Server.HTMLEncode all your variables before adding to XML string.
LVL 31

Expert Comment

ID: 16662772
or, server.urlencode the variables.

Author Comment

by:Leo Eikelman
ID: 16668096
Is these any way to allow these tags in the SOAP call instead of encoding them on the client side?

LVL 31

Expert Comment

ID: 16668241
No.  SOAP is used with XML not HTML.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Integration Management Part 2
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question