1

I'm trying to access a SOAP web service of a data vendor. The server is written in Java. I'm accessing it from Perl. Due to some specialty, I have to send original http requests myself instead of using SOAP Lite package.

The client is working fine. I can call most methods, and the response I get also looks good, which means things like request, response and namespace are all good. However, there is one method that I have trouble with. The wsdl of its request data type is as below:

<xs:element name="method1">
    <xs:complexType>
        <xs:sequence>
            <xs:element minOccurs="0" name="xmlContent" nillable="true" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

The unique part of this method is that it accepts a string element, xmlContent, which is actually xml content. And here is my request:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
    <namesp1:method1 xmlns:namesp1="http://vendor.com">
    <xmlContent xsi:type="xsd:string">
        <?xml version="1.0" encoding="UTF-8"?>
        <product id="ABC" type="CSV">
        <columns>
            <column name="DATE" format="yyyymmdd" />
            <column name="COUNTRY" format="DESC"/>
        </columns>
        </product>
    </xmlContent>
    </namesp1:method1>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I saved the request in a file, and read the file into Perl, and send the http post request. The fault string I got is: Validation Error(s): Content is not allowed in prolog.

I googled, and it seems to be Java couldn't recognize the 2nd <?xml version="1.0" encoding="UTF-8"?> line. I tried removing that line, but I got a different error: premature end of file

My questions: Am I putting the xml content part the right way? What's causing the error? How can I fix it?

simbabque
  • 53,749
  • 8
  • 73
  • 136
abisko
  • 663
  • 8
  • 21

1 Answers1

0

The data type of the xmlContent element is xsd:string. That suggests it should be one long string that contains stuff that looks like XML. That it's named xmlContent is incidental. They just chose that arbitrary name.

Try passing a string with XML in it, instead of a bunch of actual XML tags. Use CDATA to escape it like so.

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
    <namesp1:method1 xmlns:namesp1="http://vendor.com">
    <xmlContent xsi:type="xsd:string">
        <![CDATA[<?xml version="1.0" encoding="UTF-8"?>
        <product id="ABC" type="CSV">
        <columns>
            <column name="DATE" format="yyyymmdd" />
            <column name="COUNTRY" format="DESC"/>
        </columns>
        </product>]]>
    </xmlContent>
    </namesp1:method1>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Note there shouldn't be a newline or other whitespace between the <![CDATA[ and the <?xml>, because that would be seen as part of the content, and the server on the other end might choke on it when parsing that part as actual XML. The whitespace in front of the <![CDATA[ however is fine, as that is just arbitrary whitespace inside of the outer XML, which is ignored.

Community
  • 1
  • 1
simbabque
  • 53,749
  • 8
  • 73
  • 136