开发者

SOAP: looks like we got no XML document

I'm trying to create a web service but before I do I'm trying to get a simple example that I found on the internet to work first but I keep getting the following error:

Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document in C:\Documents and Settings\geoff\My Documents\Websites\jquery\index.php:20 Stack trace: #0 [internal function]: SoapClient->__call('get开发者_如何学JAVAStockQuote', Array) #1 C:\Documents and Settings\geoff\My Documents\Websites\jquery\index.php(20): SoapClient->getStockQuote(Array) #2 {main} thrown in C:\Documents and Settings\geoff\My Documents\Websites\jquery\index.php on line 20

I am using nusoap v1.94

My web service code looks like this:

function getStockQuote($symbol) {
$price = '1.23';
return $price;
}

require('nusoap.php');

$server = new soap_server();

$server->configureWSDL('stockserver', 'urn:stockquote');

$server->register("getStockQuote",
            array('symbol' => 'xsd:string'),
            array('return' => 'xsd:decimal'),
            'urn:stockquote',
            'urn:stockquote#getStockQuote');

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)
                  ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);

I know one cause is to have whitespace before or after your php tags in your server script but thats not the case. It has been driving me mad for hours! Any help would be much appreciated.


A byte order mark (BOM) would have the same effect as whitespace before the php tags. Here you find a PHP snippet to detect and remove a BOM. Be sure to configure you editor to not insert the BOM again.


Pretty late but adding my fix to benefit of others. I have got similar error when I changed my Apache server from 2.2 to 2.4 and PHP 5.4.10 to 5.6.18 on windows. Client app used php 5.6.1. To fix the problem, I have done the following:

  1. Passed SOAP version parameter to SoapClient:

    'soap_version' => SOAP_1_1

  2. On the server php.ini configuration file I have added:

    always_populate_raw_post_data = -1


A bit late, but this kinda error is often caused by server-side (SOAP sense) problem :

  • print/echo content
  • rik's answer too
  • mistake (eg I was currently having this error because of a miswritten filename in an include, generating an include error instead of executing the script...)
  • bad parameter in SOAP server
  • not the same compression level both sides (if compression used)

This message just inform you that the SOAP client did not receive well-formatted XML (eg. an error message instead of XML).


set always_populate_raw_post_data = -1 in php.ini file (by removing the ; ) and then restart the server. It worked fine for me.


This error appears also if a soap XML response contains special Unicode characters. In my case it was REPLACEMENT CHARACTER (U+FFFD).

In details, inner function of the SoapClient xmlParseDocument sets xmlParserCtxtPtr->wellFormed property as false after parsing. It throws soap fault with looks like we got no XML document.

https://github.com/php/php-src/blob/master/ext/soap/php_packet_soap.c#L46


I received this error when I was interacting with the Magento API which was loading a model, and it was throwing a warning before outputting the xml response which was causing the error.

To fix it you can simply turn off warnings on the API function: error_reporting(0);


As far as I understand, the error of the SOAP parser when it comes invalid XML.

As it was with me.

  1. Turn on the display of the error
  2. performed in try-catch and in the catch call __getLastResponse
  3. I catch another error:

Warning: simplexml_load_string(): Entity: line 1: parser error : xmlParseCharRef: invalid xmlChar value 26 in

  1. The first patient was PHP5.3. Once run the script on the PHP5.4, became more informative error - I swear on an invalid character, because of which, presumably, and fell SOAP parser.

As a result, I obtained the following code:

$params = array(...);
try
{
    $response = $client->method( $params );
}
catch(SoapFault $e)
{
    $response = $client->__getLastResponse();
    $response = str_replace("&#x1A",'',$response); ///My Invalid Symbol
    $response = str_ireplace(array('SOAP-ENV:','SOAP:'),'',$response);
    $response = simplexml_load_string($response);
}

If someone will tell in the comments what a symbol, I will be grateful.


Try to look into your server log. If you use nginx, please look into /var/log/nginx/error.log. if "Permission denied" pop up, please change related dir owner. Hope it will work.


Another possible solution...

I had the same problem, I was getting crazy. The solution was simple. Verifying my server.. cause it is a server error. My error was that i had put "rcp" instead of "rpc".


The post is old, but I think it's always helpful, because I became crazy to not understand why this error appeared.

The solution for me was here: PHP SOAP client that understands multi-part messages?.

I had to extend the SoapClient to manage the MTOM encoding to obtain a clean XML as response.

I hope it can help someone.


After years, here is another input I think would be useful for some; my case was a unit separator character returned in the body of the SAOP response, rendering the XML invalid. Therefore I needed to extend the SoapClient (a suggestion from another answer) and remove 0x1f character from the response like:

class SoapClientNoBOM extends SoapClient
{
    public function __doRequest($request, $location, $action, $version, $one_way = 0)
    {
        $response = parent::__doRequest($request, $location, $action, $version, $one_way);
        // strip away everything but the xml (including removal of BOM)
        $response = preg_replace('#^.*(<\?xml.*>)[^>]*$#s', '$1', $response);
        // also remove unit separator
        $response = str_replace("\x1f", '', $response);
        return $response;
    }
}

Now use SoapClientNoBOM instead of native SoapClient to instantiate a soap client.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜