Search code examples
javaphpsoapxml-rpc

PHP: Error calling SOAP rpc webservice from Java - Worked before


I have a java program which calls methods in php (rpc) over SOAP. Since a couple of days it does not work anylonger from my existing code. On my dev machine I recently updated to php7.0, but on the remote server there is still php5.x running. It neither works with localhost, nor with the remote server. Both machines are running Ubuntu (dev 16.04, remote 14.04)

I always get the following error:

[SOAPException: faultCode=SOAP-ENV:Client; msg=Parsing error, response was:
The processing instruction target matching "[xX][mM][lL]" is not allowed.; targetException=org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 6; 
The processing instruction target matching "[xX][mM][lL]" is not allowed.]

I tested with SOAP UI, and it works, no error. I even tested with apache axis2, but fails, too.

the problem is that the response from the php script seems to be invalid.

I looked at the encoding etc, checked if there is a new line or whatever. But I have no clue what the problem could be.

Sample soap call which works in Soap UI:

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:searchQuery xmlns:ns1="http://localhost/Server.php" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<query xsi:type="xsd:string">oil</query>
</ns1:searchQuery>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Response: When I click on validate in Soap UI, it tells me that the xml declration is not well formed. But I have no idea how to change it.

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/Server.php" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><ns1:searchQueryResponse><return xsi:type="xsd:string">{
  "prefixes": ..... }
</return></ns1:searchQueryResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

The php Code I use to initialize the soap server:

try {

    ini_set ( "soap.wsdl_cache_enabled", "0" );
    $server = new SOAPServer ( 'Server.wsdl' );
    $server->setClass ( 'Webdienst' );
    $server->handle ();
} 

catch ( SOAPFault $f ) {
    echo $f->getMessage ();
}

My wsdl file:

<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost/Server.php" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="Webdienst" targetNamespace="http://localhost/Server.php">
  <types>
    <xsd:schema targetNamespace="http://localhost/Server.php">
      <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
    </xsd:schema>
  </types>
  <portType name="WebdienstPort">
    <operation name="createRecord">
      <documentation>Create a new record</documentation>
      <input message="tns:createRecordIn"/>
      <output message="tns:createRecordOut"/>
    </operation>
    <operation name="searchQuery">
      <documentation>Search for the String</documentation>
      <input message="tns:searchQueryIn"/>
      <output message="tns:searchQueryOut"/>
    </operation>
  </portType>
  <binding name="WebdienstBinding" type="tns:WebdienstPort">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="createRecord">
      <soap:operation soapAction="http://localhost/Server.php#createRecord"/>
      <input>
        <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/Server.php"/>
      </input>
      <output>
        <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/Server.php"/>
      </output>
    </operation>
    <operation name="searchQuery">
      <soap:operation soapAction="http://localhost/Server.php#searchQuery"/>
      <input>
        <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/Server.php"/>
      </input>
      <output>
        <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/Server.php"/>
      </output>
    </operation>
  </binding>
  <service name="WebdienstService">
    <port name="WebdienstPort" binding="tns:WebdienstBinding">
      <soap:address location="http://localhost/Server.php"/>
    </port>
  </service>
  <message name="createRecordIn">
    <part name="recordURI" type="xsd:anyType"/>
    <part name="documentURI" type="xsd:anyType"/>
    <part name="content" type="xsd:anyType"/>
    <part name="fileName" type="xsd:anyType"/>
    <part name="mimeType" type="xsd:anyType"/>
    <part name="creationDate" type="xsd:anyType"/>
    <part name="datasetURI" type="xsd:anyType"/>
    <part name="translatedContent" type="xsd:anyType"/>
    <part name="alchemyTopics" type="xsd:anyType"/>
    <part name="summary" type="xsd:anyType"/>
    <part name="author" type="xsd:anyType"/>
  </message>
  <message name="createRecordOut">
    <part name="return" type="xsd:string"/>
  </message>
  <message name="searchQueryIn">
    <part name="query" type="xsd:anyType"/>
  </message>
  <message name="searchQueryOut">
    <part name="return" type="xsd:string"/>
  </message>
</definitions>

Solution

  • I found the solution after googling around.

    The problem was that I had an include() declaration at top of my soap server class which included another php file. The other php file had an empty line after the ?> closing tag. I moved the closing tag directly after the last brace and now it works!