WCF/WF - XML string as a parameter inside a SOAP request??

Asked By Vivek Roy on 24-Jul-14 08:42 AM
I have a web service method which accepts XML string as input,reads the XML string using XMLDOM and returns no. occurence(s) of a particular element...
here is my Web method code for ur kind ref....
<WebMethod()> Public Function HowManyAttachments(ByVal LegalXML As String) As Integer
        Dim objDOM As New XmlDocument()
        Dim j As Integer
        Dim iAttachments As Integer
        Dim mystr As Object
        objDOM.LoadXml(LegalXML)
        Dim objLSt As Object
        objLSt = objDOM.GetElementsByTagName("*")
        For j = 0 To objLSt.count - 1
            If objLSt(j).NAME = "DocumentContent" Then
                iAttachments = iAttachments + 1
            End If
        Next
        HowManyAttachments = iAttachments
        objLSt = Nothing
        objDOM = Nothing
I tried sending an XML string as a parameter inside a SOAP request to this web service method thru' an asp page using XMLHTTP object...
here is my SOAP request XML....
<?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>
<m:HowManyAttachments xmlns:m="http://tempuri.org/">
<LegalXML>
	My XML as a string goes here......
</LegalXML>
</m:HowManyAttachments>
</soap:Body>
</soap:Envelope>
I got the SOAP response but the result returned is as follows meaning that the web method is not able to extract the parameter value from the XML string sent to it thru' an SOAP request....
<?xml version="1.0"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <soap:Fault> <faultcode>soap:Server</faultcode> <faultstring>System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentNullException: Value cannot be null. Parameter name: s at System.IO.StringReader..ctor(String s) at System.Xml.XmlDocument.LoadXml(String xml) at FirstWebService.EFWebService.HowManyAttachments(String LegalXML) in c:\inetpub\wwwroot\FirstWebService\EFWebService.asmx.vb:line 49 --- End of inner exception stack trace ---</faultstring> <detail/> </soap:Fault> </soap:Body> </soap:Envelope> 
I would like if it is really possible to send an XML as a string inside a SOAP request...??
if yes,then how do i get rid of the above problem...???

Need to use CDATA section - Asked By Peter Bromberg on 15-Nov-02 12:56 PM

in the xml element that encloses your XML string. This tells the parser
to treat the contents of the element as literal text and not try to parse it.
Look up the CDATA syntax in your xml docs.

web services taking xml string as a parameter - dilip v replied to Vivek Roy on 01-May-08 09:22 AM

when you pass XML string as a parameter to a web service it contradicts with the WSDL.It looks for a WSDL with the complete XML u sent out.try with disconnected or trying passing using a single Quote where ur XML string starts

<?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>
<m:HowManyAttachments xmlns:m="http://tempuri.org/">;
<LegalXML>
'<employee><eid></eid></employee>'

</LegalXML>
</m:HowManyAttachments>
</soap:Body>
</soap:Envelope>

CDATA tags worked for me! - Dakota Thompson replied to Peter Bromberg on 24-Jul-14 08:42 AM

This was giving me a headache for a couple hours. CDATA tags cleared it right up.