I'm trying to get some data from a WebService using SOAP request. The SOAP body should contain an SQL query. Whenever I'm using the <
character it causes the above mentioned error at SOAPReqBody.LoadXml()
. How can I fix this?
HttpWebRequest request = CreateSOAPWebRequest();
XmlDocument SOAPReqBody = new XmlDocument();
SOAPReqBody.LoadXml(@"<?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>
<Query xmlns=""http://LifaOIS.DK/OISService"">
<UID>" + uid + @"</UID>
<PWD>" + pwd + @"</PWD>
<SQL>" + sql + @"</SQL>
<Meta>" + meta + @"</Meta>
</Query>
</soap:Body>
</soap:Envelope>");
This is ugly but if you really have to carry a SQL query within the message payload and the less than '<' character is a problem within the XML and you can't control packing and unpacking of the payload, then you might like to consider using BETWEEN...
WHERE field NOT EQUAL minValue AND field BETWEEN minvalue AND upperValue
Note that BETWEEN's from and to values are inclusive - hence the need for the exclusion of minValue
Have you tried wrapping your sql
in <.[CDATA[...]]>
?
Like:
<SQL><![CDATA[" + sql + @"]]></SQL>
Instead of
<SQL>" + sql + @"</SQL>
See What does <?[CDATA[]]> in XML mean? for more details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.