Any string that can be represented using a CDATA section can also be represented as simple element content, provided that '<' and '&' characters are correctly escaped, i.e. replaced by < and & (in your case the XML serializer takes care of this). The converse is actually not true, i.e. there are strings that can't be represented using a CDATA section. That means that you will never get into a situation where a CDATA section is required, except of course if the service explicitly checks that a CDATA section is used. That however is extremely unlikely for services deployed on a decent SOAP stack (including .NET), and the test you have done shows that this is not the case here.
Andreas On Tue, Jan 24, 2012 at 16:07, Janardhanan, Suresh B <[email protected]> wrote: > Andreas, > > > > Thank you very much for your suggestion. Yes, if I pass just the XML without > the CDATA Begin and End Tag the .Net web service comes back with a valid > response. > > <PARAMETERS><RETURN><GENERALINFORMATION><INFORMATIONRETURNTYPEID>3294f665bc644359bfd15824d2efe29c</INFORMATIONRETURNTYPEID></GENERALINFORMATION></RETURN></PARAMETERS> > > > > I am not sure why that’s the case. The reason the .Net web service has CDATA > Begin and End tag wrapped around the XML is to treat it as a string value, > even if It is not a well-formed XML. I am working on testing this solution > against all the WSDL Operations and check if works correctly. > > > > Thanks again for your direction. > > > > Suresh > > > > Hi, > > > > I generated my web services client using Apache Axis v2.1.6.1. The .Net > target web service has the following in its WSDL – > > > > <wsdl:part name="sXmlParameters" type="s:string" /> > > > > I am expected to set the following string for sXmlParameters. > > xmlParameters=<![CDATA[<PARAMETERS><RETURN><GENERALINFORMATION><INFORMATIONRETURNTYPEID>3294f665bc644359bfd15824d2efe29c</INFORMATIONRETURNTYPEID></GENERALINFORMATION></RETURN></PARAMETERS> > > > > When it is sent through Apache Axis client, the XML characters <, > are > getting converted – > > [main] DEBUG httpclient.wire.content - >> "<?xml version='1.0' > encoding='UTF-8'?><soapenv:Envelope > xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><ns1:RetrieveByParameter > xmlns:ns1="http://wsdl.echelon.com/Panoramix/"><sKey>e1839da0c11c4058928b650f97c06853</sKey><sIDTypeID>f76e5d708edd464593bb031f646990b6</sIDTypeID><sID>100063728</sID><sXmlParameters><![CDATA[<PARAMETERS><RETURN><GENERALINFORMATION><INFORMATIONRETURNTYPEID>3294f665bc644359bfd15824d2efe29c</INFORMATIONRETURNTYPEID></GENERALINFORMATION></RETURN></PARAMETERS>]]></sXmlParameters></ns1:RetrieveByParameter></soapenv:Body></soapenv:Envelope>" > > > > Is there any way to send the XML string as is? > > > > I also tried changing the WSDL type, which resulted in an Exception. > > > > This is what I changed in the WSDL - changed sXmlParameters type=s:string to > xmlStingType as shown below. > > <wsdl:types> > > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > > targetNamespace="http://wsdl.echelon.com/Panoramix/"> > > <xsd:complexType name="xmlStringType"> > > <xsd:sequence> > > <xsd:any > xmlns:xsd="http://www.w3.org/2001/XMLSchema"/> > > </xsd:sequence> > > </xsd:complexType> > > </xsd:schema> > > </wsdl:types> > > <wsdl:part name="sXmlParameters" type="tns:xmlStringType" /> > > > > Code Snippet: > > XmlStringType xmlStrType = new XmlStringType(); > > OMElement element = AXIOMUtil.stringToOM(xmlParameters); > > xmlStrType.setExtraElement(element); > > > > Stack Trace: > > Caused by: > > org.apache.axiom.om.OMException: > com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'C' (code > 67) (CDATA not allowed in prolog/epilog) > > at [row,col {unknown-source}]: [1,3] > > Stack Trace: > > > org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:297) > > > org.apache.axiom.om.impl.llom.OMDocumentImpl.getOMDocumentElement(OMDocumentImpl.java:111) > > > org.apache.axiom.om.impl.builder.StAXOMBuilder.getDocumentElement(StAXOMBuilder.java:571) > > > org.apache.axiom.om.impl.builder.StAXOMBuilder.getDocumentElement(StAXOMBuilder.java:567) > > org.apache.axiom.om.util.AXIOMUtil.stringToOM(AXIOMUtil.java:54) > > org.apache.axiom.om.util.AXIOMUtil.stringToOM(AXIOMUtil.java:39) > > > > Any help is much appreciated. > > > > Thanks, > > Suresh > >
