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 SettingsgeoffMy DocumentsWebsitesjqueryindex.php:20 Stack trace: #0 [internal function]: SoapClient->__call('getStockQuote', Array) #1 C:Documents and SettingsgeoffMy DocumentsWebsitesjqueryindex.php(20): SoapClient->getStockQuote(Array) #2 {main} thrown in C:Documents and SettingsgeoffMy DocumentsWebsitesjqueryindex.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.
asked Nov 30, 2010 at 12:51
0
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.
answered Nov 30, 2010 at 15:49
rikrik
8,5441 gold badge26 silver badges21 bronze badges
0
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:
-
Passed SOAP version parameter to SoapClient:
‘soap_version’ => SOAP_1_1
-
On the server php.ini configuration file I have added:
always_populate_raw_post_data = -1
answered Feb 16, 2016 at 10:35
mvsagarmvsagar
1,9082 gold badges17 silver badges19 bronze badges
0
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).
answered Sep 7, 2012 at 13:24
BenjBenj
1,1747 gold badges26 silver badges57 bronze badges
0
set always_populate_raw_post_data = -1 in php.ini file (by removing the ; ) and then restart the server. It worked fine for me.
answered Jan 10, 2017 at 13:09
Ipsita RoutIpsita Rout
4,7353 gold badges36 silver badges40 bronze badges
0
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
answered Oct 13, 2015 at 16:22
![]()
Andrei ZhamoidaAndrei Zhamoida
1,4381 gold badge20 silver badges30 bronze badges
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);
answered May 21, 2012 at 5:32
KusKus
2,51926 silver badges27 bronze badges
2
As far as I understand, the error of the SOAP parser when it comes invalid XML.
As it was with me.
- Turn on the display of the error
- performed in try-catch and in the catch call __getLastResponse
- I catch another error:
Warning: simplexml_load_string(): Entity: line 1: parser error :
xmlParseCharRef: invalid xmlChar value 26 in
- 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("",'',$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.
answered Jul 21, 2016 at 8:29
![]()
borodatychborodatych
2864 silver badges9 bronze badges
2
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.
answered May 14, 2014 at 8:25
![]()
BoushBoush
1511 silver badge6 bronze badges
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».
answered Mar 23, 2015 at 17:16
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.
answered Jun 1, 2020 at 8:39
JiizenJiizen
1191 silver badge11 bronze badges
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.
answered Feb 2, 2021 at 21:51
TurabTurab
1721 silver badge11 bronze badges
i’m trying to use magento soapV2 to create product, here is the script:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<?php
// Magento login information
$mage_url = 'http://localhost/first/api/v2_soap?wsdl=1';
$mage_user = 'rayapi';
$mage_api_key = 'Abcd1234';
// Initialize the SOAP client
$client = new SoapClient( $mage_url );
$session = $client->login( $mage_user, $mage_api_key );
$catalogProductCreateEntity = new stdClass();
$additionalAttrs = array();
$catalogProductCreateEntity->name = "product name";
$catalogProductCreateEntity->description = "description";
$catalogProductCreateEntity->short_description = "desc";
$catalogProductCreateEntity->status = "1";
$catalogProductCreateEntity->price = "99";
$catalogProductCreateEntity->tax_class_id = "2";
$catalogProductCreateEntity->websites = array(1,2);
$catalogProductCreateEntity->categories = array(7,15);
$catalogProductCreateEntity->status = 1;
$catalogProductCreateEntity->price = 45;
$catalogProductCreateEntity->tax_class_id = 2;
$catalogProductCreateEntity->weight = 1;
// send the request
$product = $client->catalogProductCreate($session, "simple", 9, 'test_sku', $catalogProductCreateEntity);
// end session and enjoy your updated products :)
$client->endSession($session);
var_dump($product);
?>
Error message:
Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document in C:xampphtdocsfirstsoap.php:71 Stack trace: #0 C:xampphtdocsfirstsoap.php(71): SoapClient->__call('catalogProductC...', Array) #1 C:xampphtdocsfirstsoap.php(71): SoapClient->catalogProductCreate('7ab47f189292d99...', 'simple', 9, 'test_sku', Object(stdClass)) #2 {main} thrown in C:xampphtdocsfirstsoap.php on line 71
i tried use
$result = $client->catalogInventoryStockItemList($session, array(‘693’)); // //Products ID
print_r($result);
catalogInventoryStockItemList is work for me but catalogProductCreate not work.
i googled around but their solution not useful to me, how to solve this problem?
Hi guys. I’m using the same code that I used to connect to a different exchange server previously. I’ve been trying, with no success, to connect to a different server. I am getting the following errors/exceptions:
Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document in /var/www/html/ews_exchange/ms_exchange/ExchangeWebServices.php:327
Stack trace:
#0 /var/www/html/ews_exchange/ms_exchange/ExchangeWebServices.php(327): SoapClient->__call(‘FindItem’, Array)
#1 /var/www/html/ews_exchange/ms_exchange/ExchangeWebServices.php(327): NTLMSoapClient_Exchange->FindItem(Object(EWSType_FindItemType))
#2 /var/www/html/ews_exchange/ms_exchange/get_contacts_test.php(70): ExchangeWebServices->FindItem(Object(EWSType_FindItemType))
#3 /var/www/html/ews_exchange/ms_exchange/get_contacts_test.php(87): get_exchange_contacts(‘autodiscover.hp…’, ‘Trixy’, ‘helloworld’, ‘Exchange2010’)
#4 {main}
thrown in /var/www/html/ews_exchange/ms_exchange/ExchangeWebServices.php on line 327
Any help would be greatly appreciated. If you need to know anything else, I’m happy to help.
Paul.
Today, I was thinking of using soap to develop related interfaces to call cooperating companies, but I encountered this error. After a long search and a long search at google, none of them were problems I encountered. However, in the end, I found that the error was related to the size of the data transferred by soapserver (I don’t know whether this description is appropriate or not). When I get 10 pieces of data from the database, I can easily use soapclient to get the data, but when I query 1000 pieces of data from the database inside, I will report an error (“Fatal Error: Uncausght SOAP Fault Exception: [Client] Looks Like We Gotno XML Document in …”)! If I run the person.class.php program directly, I can display the complete xml document. Does the environmental configuration of this server matter? I don’t know much about soap, and I just learn to sell it now. I hope experienced predecessors can give me some advice. Thank you very much!
The following is my program code:
<?php
//person.class.php文件
class person
{
public function getInfo()
{
$strGetList = 'SELECT * FROM information LIMIT 100';
$GLOBALS['le']->query($strGetList);
$results = array();
$xmlString = "<?xml version="1.0" encoding="utf-8"?>n";
$xmlString .="<Data>n";
while( $rows = $GLOBALS['le']->fetch_assoc() ) {
$results[] = $rows;
}
foreach($results as $key=>$val) {
$xmlString .="<Rec ID='UU{$key}'>n";
foreach($val as $k=>$v ) {
if(strlen($v)>0) {
$v = htmlspecialchars($v);
$xmlString .=" <UU{$k}>$v</UU{$k}>n";
}
}
$xmlString .="</Rec>n";
}
$xmlString .="</Data>n";
return $xmlString;
}
}
//$p = new person;
//echo $p->getInfo();//经测试xml中可以显示所有数据
--- 分割线 ---
<?php
//server.php文件
include("person.class.php");
$server = new SoapServer(null,array('uri'=>'abcd','encoding'=>'UTF-8'));
$server->setClass('person');
$server->handle();
--- 分割线 ---
<?php
//client.php文件
try{
$soap = new SoapClient(null,array(
'location'=>'http://192.168.1.126:102/server.php',
'uri'=>'abcd',
'encoding' => 'UTF-8',
));
$s1 =$soap->__soapCall('getInfo',array());
echo $s1;
} catch(Exction $e) {
echo $e->getMessage();
}
Judging from the exception “[client] looks like we gotno xmldocument” of SoapClient, there should be a problem with the response, so the first thing to do is to check what the response message is, and there are several schemes to help you locate the problem:
- Simple, you can use itSoapUI, to see if there is really a problem with the response? Is there no response?
- Geek bit by bit, make a simulation client to check the response message, ordinary SOAP protocol is not difficult, just use HTTP protocol POST a small piece of XML to the Server, the code amount should be within 20 lines
- I usually use it a little bit, because SOAP uses HTTP transport protocol, so I can grab the whole HTTP Response and check whether its contents conform to XML format. The grabbing method can be usedTCPDUMP(Linux Command Line) orHTTPTracer(Java cross-platform, easy to use, my favorite)
- To be more direct, check the source code of SoapClient.php. If I remember correctly, the amount of code is quite small. Look for the string “looks like we got no XML document” and then go back to the XML parsing section. Before parsing, output the original content to see what is wrong with the response content.
I’m getting crazy with this error I’ve tried all issues in forums nothing works I’m getting disappointed. Help Please with this
PHP Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document
Please guys,I would really appreciate the help
asked May 13, 2013 at 8:15
bee1tbee1t
211 gold badge1 silver badge5 bronze badges
6
This error occurs when the response from the soap server cannot be parsed as XML.
Reasons for this:
- The HTTP body of the response has the wrong
Content-Type. - The content is no XML at all, because the PHP script triggered a fatal error, or an uncatched exception, or simply
die()d. - The content contains PHP error output like notices, warnings etc.
How to see what it is?
Use a different soap client, like soapUI. This one will display what you got as response, even if it isn’t parsable XML.
answered May 17, 2013 at 18:15
SvenSven
68.3k10 gold badges106 silver badges108 bronze badges
I’m getting crazy with this error I’ve tried all issues in forums nothing works I’m getting disappointed. Help Please with this
PHP Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document
Please guys,I would really appreciate the help
asked May 13, 2013 at 8:15
bee1tbee1t
211 gold badge1 silver badge5 bronze badges
6
This error occurs when the response from the soap server cannot be parsed as XML.
Reasons for this:
- The HTTP body of the response has the wrong
Content-Type. - The content is no XML at all, because the PHP script triggered a fatal error, or an uncatched exception, or simply
die()d. - The content contains PHP error output like notices, warnings etc.
How to see what it is?
Use a different soap client, like soapUI. This one will display what you got as response, even if it isn’t parsable XML.
answered May 17, 2013 at 18:15
SvenSven
68.3k10 gold badges106 silver badges108 bronze badges
- Introduction
- Installing/Configuring
- Requirements
- Installation
- Runtime Configuration
- Resource Types
- Predefined Constants
- SOAP Functions
- is_soap_fault — Checks if a SOAP call has failed
- use_soap_error_handler — Set whether to use the SOAP error handler
- SoapClient — The SoapClient class
- SoapClient::__call — Calls a SOAP function (deprecated)
- SoapClient::__construct — SoapClient constructor
- SoapClient::__doRequest — Performs a SOAP request
- SoapClient::__getCookies — Get list of cookies
- SoapClient::__getFunctions — Returns list of available SOAP functions
- SoapClient::__getLastRequest — Returns last SOAP request
- SoapClient::__getLastRequestHeaders — Returns the SOAP headers from the last request
- SoapClient::__getLastResponse — Returns last SOAP response
- SoapClient::__getLastResponseHeaders — Returns the SOAP headers from the last response
- SoapClient::__getTypes — Returns a list of SOAP types
- SoapClient::__setCookie — Defines a cookie for SOAP requests
- SoapClient::__setLocation — Sets the location of the Web service to use
- SoapClient::__setSoapHeaders — Sets SOAP headers for subsequent calls
- SoapClient::__soapCall — Calls a SOAP function
- SoapServer — The SoapServer class
- SoapServer::addFunction — Adds one or more functions to handle SOAP requests
- SoapServer::addSoapHeader — Add a SOAP header to the response
- SoapServer::__construct — SoapServer constructor
- SoapServer::fault — Issue SoapServer fault indicating an error
- SoapServer::getFunctions — Returns list of defined functions
- SoapServer::handle — Handles a SOAP request
- SoapServer::setClass — Sets the class which handles SOAP requests
- SoapServer::setObject — Sets the object which will be used to handle SOAP requests
- SoapServer::setPersistence — Sets SoapServer persistence mode
- SoapFault — The SoapFault class
- SoapFault::__construct — SoapFault constructor
- SoapFault::__toString — Obtain a string representation of a SoapFault
- SoapHeader — The SoapHeader class
- SoapHeader::__construct — SoapHeader constructor
- SoapParam — The SoapParam class
- SoapParam::__construct — SoapParam constructor
- SoapVar — The SoapVar class
- SoapVar::__construct — SoapVar constructor
nodkz at mail dot ru ¶
14 years ago
PROBLEM (with SOAP extension under PHP5) of transferring object, that contains objects or array of objects. Nested object would not transfer.
SOLUTION:
This class was developed by trial and error by me. So this 23 lines of code for most developers writing under PHP5 solves fate of using SOAP extension.
<?php
/*
According to specific of organization process of SOAP class in PHP5, we must wrap up complex objects in SoapVar class. Otherwise objects would not be encoded properly and could not be loaded on remote SOAP handler.
Function "getAsSoap" call for encoding object for transmission. After encoding it can be properly transmitted.
*/
abstract class SOAPable {
public function getAsSOAP() {
foreach($this as $key=>&$value) {
$this->prepareSOAPrecursive($this->$key);
}
return $this;
}
private function
prepareSOAPrecursive(&$element) {
if(is_array($element)) {
foreach($element as $key=>&$val) {
$this->prepareSOAPrecursive($val);
}
$element=new SoapVar($element,SOAP_ENC_ARRAY);
}elseif(is_object($element)) {
if($element instanceof SOAPable) {
$element->getAsSOAP();
}
$element=new SoapVar($element,SOAP_ENC_OBJECT);
}
}
}// ------------------------------------------
// ABSTRACT EXAMPLE
// ------------------------------------------class PersonList extends SOAPable {
protected $ArrayOfPerson; // variable MUST be protected or public!
}
class
Person extends SOAPable {
//any data
} $client=new SoapClient("test.wsdl", array( 'soap_version'=>SOAP_1_2, 'trace'=>1, 'classmap' => array('Person' => "Person", 'PersonList' => "PersonList") ));$PersonList=new PersonList;// some actions$PersonList->getAsSOAP();$client->someMethod($PersonList);?>
So every class, which will transfer via SOAP, must be extends from class SOAPable.
As you can see, in code above, function prepareSOAPrecursive search another nested objects in parent object or in arrays, and if does it, tries call function getAsSOAP() for preparation of nested objects, after that simply wrap up via SoapVar class.
So in code before transmitting simply call $obj->getAsSOAP()
Ryan ¶
14 years ago
If you are having an issue where SOAP cannot find the functions that are actually there if you view the wsdl file, it's because PHP is caching the wsdl file (for a day at a time). To turn this off, have this line on every script that uses SOAP: ini_set("soap.wsdl_cache_enabled", "0"); to disable the caching feature.
Raphal Gertz ¶
13 years ago
Juste a note to avoid wasting time on php-soap protocol and format support.
Until php 5.2.9 (at least) the soap extension is only capable of understanding wsdl 1.0 and 1.1 format.
The wsdl 2.0, a W3C recommendation since june 2007, ISN'T supported in php soap extension.
(the soap/php_sdl.c source code don't handle wsdl2.0 format)
The wsdl 2.0 is juste the 1.2 version renamed because it has substantial differences from WSDL 1.1.
The differences between the two format may not be invisible if you don't care a lot.
The wsdl 1.0 format structure (see http://www.w3.org/TR/wsdl) :
<definitions ...>
<types ...>
</types>
<message ...>
<part ...>
</message>
<portType ...>
<operation ...>
<input ... />
<output ... />
<fault ... />
</operation>
</portType>
<binding ...>
<operation ...>
<input ... />
<output ... />
<fault ... />
</operation>
</binding>
<service ...>
<port ...>
</service>
</definitions>
And the wsdl 2.0 format structure (see http://www.w3.org/TR/wsdl20/) :
<description ...>
<types ...>
</types>
<interface ...>
<fault ... />
<operation ...>
<input ... />
<output ... />
<fault ... />
</operation>
</interface>
<binding ...>
<fault ... />
<operation ...>
<input ... />
<output ... />
<fault ... />
</operation>
</binding>
<service ...>
<endpoint ...>
</service>
</description>
The typical error message if you provide a wsdl 2.0 format file :
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't find <definitions> in 'wsdl/example.wsdl' in /path/client.php on line 9
Luke ¶
7 years ago
Was calling an asmx method like $success=$x->AuthenticateUser($userName,$password) and this was returning me an error.
However i changed it and added the userName and password in an array and its now KAWA...
moazzam at moazzam-khan dot com ¶
13 years ago
If anyone is trying to use this for accessing Sabre's web services, it won't work. Sabre checks the request header "Content-Type" to see if it is "text/xml" . If it is not text/xml then it sends an error back.
You will need to create a socket connection and use that to send the request over.
stephenlansell at gmail dot com ¶
12 years ago
Here is an example of a php client talking to a asmx server:
<?php
$soapClient
= new SoapClient("https://soapserver.example.com/blahblah.asmx?wsdl");
// Prepare SoapHeader parameters
$sh_param = array(
'Username' => 'username',
'Password' => 'password');
$headers = new SoapHeader('http://soapserver.example.com/webservices', 'UserCredentials', $sh_param);
// Prepare Soap Client
$soapClient->__setSoapHeaders(array($headers));
// Setup the RemoteFunction parameters
$ap_param = array(
'amount' => $irow['total_price']);
// Call RemoteFunction ()
$error = 0;
try {
$info = $soapClient->__call("RemoteFunction", array($ap_param));
} catch (SoapFault $fault) {
$error = 1;
print("
alert('Sorry, blah returned the following ERROR: ".$fault->faultcode."-".$fault->faultstring.". We will now take you back to our home page.');
window.location = 'main.php';
");
}
if (
$error == 0) {
$auth_num = $info->RemoteFunctionResult;
if (
$auth_num < 0) {
....
// Setup the OtherRemoteFunction() parameters
$at_param = array(
'amount' => $irow['total_price'],
'description' => $description);
// Call OtherRemoteFunction()
$trans = $soapClient->__call("OtherRemoteFunction", array($at_param));
$trans_result = $trans->OtherRemoteFunctionResult;
....
} else {
// Record the transaction error in the database
// Kill the link to Soap
unset($soapClient);
}
}
}
}
?>
rafinskipg at gmail dot com ¶
10 years ago
Support for MTOM addign this code to your project:
<?php
class MySoapClient extends SoapClient
{
public function __doRequest($request, $location, $action, $version, $one_way = 0)
{
$response = parent::__doRequest($request, $location, $action, $version, $one_way);
// parse $response, extract the multipart messages and so on
//this part removes stuff
$start=strpos($response,'<?xml');
$end=strrpos($response,'>');
$response_string=substr($response,$start,$end-$start+1);
return($response_string);
}
}?>
Then you can do this
<?php
new MySoapClient($wsdl_url);
?>
dennis at pleasedontspam dot clansman dot nl ¶
11 years ago
When you receive the soapfault message: "looks like we got no XML document" it might be that you're talking to a server that supports MTOM (http://www.w3.org/TR/soap12-mtom/).
MTOM is, as of yet (5.3.6), not supported by the SoapClient.
spectrumcat at gmail dot com ¶
7 years ago
In case you'll get a .p12 certificate for your SOAP client to use (or any other actually) make sure to convert it to PEM and merge with the private key.
Convert p12 to PEM with merged private key:
openssl pkcs12 -in supplied_cert.p12 -out php_soap_cert.pem -clcerts
Example:
$wsdl = "./mywsdl.wsdl"; // Or "http://provider.com/api/api.wsdl"
$options = [
'location' => "http://provider.com/api/",
'local_cert' => "./php_soap_cert.pem",
'passphrase' => "certificate_password",
];
try {
$soapClient = new SoapClient($wsdl, $options);
} catch(Exception $e) {
var_dump($e);
}
aeg at mallxs dot nl ¶
14 years ago
SoapFault exception: [SOAP-ENV:Client] looks like we got no XML document
This error can have to reasons:
1: Your server script has some hidden output like spaces before or afher <?php ... ?> or echoing some text
2: You have a bug in your server script;
resulting in a error message output
Test your server script by calling it direct from the browser.
The result should be a clean output like :
−<SOAP-ENV:Envelope>
−<SOAP-ENV:Body>
−<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring>Bad Request. Can't find HTTP_RAW_POST_DATA</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This tell's you there was a request but without data; This is OK
Now if you get the error when calling with your soap client;
remember that your server now will call other functions in the server.php script because it now has some data to process
vishal dot thakkar at exateam dot com ¶
12 years ago
I was trying to figure out for days and days to make SOAP server return an associative array and NOT an object ....
To get an array (not object) in the SOAP response, just serialize the array before returning it to the clent..
hope it helps...
Thanks.....
Vishal Thakkar.
jeff at jeffrodriguez dot com ¶
13 years ago
Named parameters are actually super easy once you know how to do it. No need to bother with SoapParam or SoapVar for the most part.
The code:
<?php
$ws->getAsset(array(
'assetId' => 5967
));
?>
Generates the following SOAP body: (formatted for readability)
<SOAP-ENV:Body>
<ns1:getAsset>
<assetId>5967</assetId>
</ns1:getAsset>
</SOAP-ENV:Body>
mariamr at gmail dot com ¶
12 years ago
“SOAP-ERROR: Parsing WSDL: Couldn’t find in ‘PATH/TO/YOUR/WSDL’”
This error occurs because some versions of PHP SOAP client do not send the user name and password that you pass as the options input parameter of the SoapClient constructor . Yu need to pass the credentials in the web service URL like this:
$soapClient =new SoapClient(“http://user:password@example.com/blahblah.wsdl”);
ivan dot cubillas at xeridia dot com ¶
14 years ago
The problem with the PHP WebService Client
We've a JAVA WebService Server which could have attached documents. When the PHP Client send the dates, the Server take it correctly, but when
the server return it to the PHP Client, the client reply always that is not a XML valid document.
The problem could be than the JAVA Server adds (to this type of XML binary files) the documentType head: xml+xop and the clean doesn't understand
this head as a XML document.
There is some possibility to solve this problem in the PHP Client without doing changes in the JAVA Server?
beau dot scott at gmail dot com ¶
14 years ago
If you've been trying to send null to a service that considers empty property tags as empty strings rather than null, here's an extending class that fixes this using xsi:nil:
<?php
class XSoapClient extends SoapClient
{
const XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";
const _NULL_ = "xxx_replacedduetobrokephpsoapclient_xxx";
protected
$mustParseNulls = false;
public function
__doRequest($request, $location, $action, $version, $one_way = null)
{
if($this->mustParseNulls)
{
$this->mustParseNulls = false;
$request = preg_replace('/<ns1:(w+)>'.self::_NULL_.'</ns1:\1>/',
'<ns1:$1 xsi:nil="true"/>',
$request, -1, &$count);
if (
$count > 0)
{
$request = preg_replace('/(<SOAP-ENV:Envelope )/',
'\1 xmlns:xsi="'.self::XSI_NS.'" ',
$request);
}
}
return parent::__doRequest($request, $location, $action, $version, $one_way);
}
public function
__call($method, $params)
{
foreach($params as $k => $v)
{
if($v === null)
{
$this->mustParseNulls = true;
$params[$k] = self::_NULL_;
}
}
return parent::__call($method, $params);
}
}
?>
Sometimes while doing soap call, it does not return the response result due to an invalid character “” in XML response and throws soap error as “looks like we got no XML document”.
Below code snippet is a simple workaround for this problem.
try
{
$client = new SoapClient('url');
$response = $client->GetPosts($request_data);
/** if xml is not well formed due to invalid character, it will throw error.
* so you can do some trick in catch part to get the result as you expect.
*/
$result = $response->GetPostsResult;
return $result;
}
catch (Exception $e)
{
/** You can get the returned response XML from __getLastResponse() and process
* it to make it in the format that you want it to be returned.
*/
$response_xml = $client->__getLastResponse();
if ( ! empty($response_xml)) {
//Replace the invalid character with blank space.
//Add multiple invalid characters in array as below if required.
//$response_xml = str_replace(array('', 'other characters'), '', $response_xml);
$response_xml = str_replace('', '', $response_xml);
//Convert all element in xml format like "soap:Envelope" as "soapEnvelope"
$response_xml = preg_replace("/(]*>)/", "$1$2$3", $response_xml);
//Interprets xml string into an object
$response_xml = simplexml_load_string($response_xml);
//returned objects will be converted into associative arrays.
$response_xml = json_decode(json_encode($response_xml));
//Finally return your response as you expected from normal return without error.
return $response_xml->soapBody->GetPostsResponse->GetPostsResult;
}
}
За последние 24 часа нас посетили 8992 программиста и 810 роботов. Сейчас ищут 294 программиста …
-

MichaelPak
Активный пользователь- С нами с:
- 5 авг 2011
- Сообщения:
- 46
- Симпатии:
- 0
Пытаюсь освоить веб сервис SOAP.
Есть сервер, вызываю метод следующим кодом:-
$p2p[‘a’]=array(‘name’ => 0, ‘password’ => ‘123’);
-
$client=new SoapClient(‘example.wsdl’);
-
$arr=$client->__getFunctions();
-
$str=$client->__soapCall(‘testMethod’,array($p2p));
-
echo ‘<br> asd <br>’.$e->__toString();
-
$client->_getLastResponse();
Вылазеет ошибка:
-
SoapFault exception: [Client] looks like we got no XML document in script.php:9 Stack trace #0 script.php(9): SoapClient->__soapCall(‘testMethod’, Array) #1 {main}
Ругается на __soapCall(). Не совсем понимаю, как загонять параметры в __soapCall().
Что туда надо: ассоциативный массив или XML? -

AndreJM
Активный пользователь- С нами с:
- 25 янв 2012
- Сообщения:
- 522
- Симпатии:
- 0
Что-то я не вижу смысла в низкоуровневом вызове.
-
$client->testMethod($p2p);
-

MichaelPak
Активный пользователь- С нами с:
- 5 авг 2011
- Сообщения:
- 46
- Симпатии:
- 0
Вот такая ошибка выскакивает при $client->__soapCall(‘testMethod’,array(‘p2p’ => $p2p)):
-
__toString(): SoapFault exception: [Client] looks like we got no XML document in /home/… Stack trace: #0 /home/… : SoapClient->__soapCall(‘testMethod’, Array) #1 {main}
-
__getMessage(): looks like we got no XML document
-
__getTraceAsString(): #0 /home/…: SoapClient->__soapCall(‘testMethod’, Array) #1 {main}
И вот такая ошибка при $client->testMethod(array(‘p2p’ => $p2p)):
-
__toString(): SoapFault exception: [Client] SOAP-ERROR: Encoding: object hasn’t ‘auth’ property in /home/… Stack trace: #0 /home/… : SoapClient->__call(‘testMethod’, Array) #1 /home/… : SoapClient->testMethod(Array) #2 {main}
-
__getMessage(): SOAP-ERROR: Encoding: object hasn’t ‘auth’ property
-
__getTraceAsString(): #0 /home/… : SoapClient->__call(‘testMethod’, Array) #1 /home/… : SoapClient->testMethod(Array) #2 {main}
-

AndreJM
Активный пользователь- С нами с:
- 25 янв 2012
- Сообщения:
- 522
- Симпатии:
- 0
Второй эррор говорит, что отсутствует проперти auth в передаваемых параметрах testMethod
-

MichaelPak
Активный пользователь- С нами с:
- 5 авг 2011
- Сообщения:
- 46
- Симпатии:
- 0
auth — это одно из переменных ассоциативного массива, забыл исправить. То есть выглядит это так:
-
$p2p[‘auth’]=array(‘name’ => ‘bla-bla-bla’, ‘password’ => ‘bla-bla-bla’);
Но даже если я строчку эту закоменчу, ошибка такая же.