Passing HTML tags in a SOAP call

Posted on 2006-05-11
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="""" xmlns:xsd="""" xmlns:soap="""">" & _
                  "<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") "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="" xmlns:xsi="" xmlns:xsd="">
- <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
    LVL 31

    Accepted Solution

    probably need to Server.HTMLEncode all your variables before adding to XML string.
    LVL 31

    Expert Comment

    or, server.urlencode the variables.
    LVL 8

    Author Comment

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

    LVL 31

    Expert Comment

    No.  SOAP is used with XML not HTML.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Highlight a word from some text 16 35
    syntax error on ASP ? 6 34
    Age between date range query (SP) 13 39
    SQL Filter Question 8 58
    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now