Page 1 of 1
Soap Error
Posted: Fri Aug 31, 2007 2:17 am
by phpcoder
HI,
I am posting this again please is there some one to help me. I wrote a simple client in php to access soap service, when I try to run client I got following error:
Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in C:\wamp\www\testsoap.php:10 Stack trace: #0 [internal function]: SoapClient->__call('PlaceOrder', Array) #1 C:\wamp\www\testsoap.php(10): SoapClient->PlaceOrder(1, 2, 3, 4) #2 {main} thrown in C:\wamp\www\testsoap.php on line 10
Please help me to write this soap client.
Thanks
Client.php
Code: Select all
$client = new SoapClient('http://192.168.1.74/starwstest/wmsorderfulfilment.asmx?WSDL');
$response = $client->CancelOrder('SOR01212')
Posted: Fri Aug 31, 2007 3:43 am
by aceconcepts
Object reference not set to an instance of an object
This seems to hint at the problem. Can you show your code up to line 10 of testsoap.php?
Posted: Fri Aug 31, 2007 4:50 am
by phpcoder
aceconcepts wrote:Object reference not set to an instance of an object
This seems to hint at the problem. Can you show your code up to line 10 of testsoap.php?
Code: Select all
<?php
class Test {
public $ordno;
}
$parameters = new Test;
$parameters -> ordno = "SOR01212";
$array[0] = "SOR01212";
$client = new SoapClient('http://www.perfumefirst.co.uk/ws.wsdl');
[Line#10]$response = $client->CancelOrder('SORO1214545');
?>
I got this error on calling any of the function of the wsdl file.
Posted: Fri Aug 31, 2007 5:24 am
by volka
First please try something simpler
Code: Select all
<?php
$client = new SoapClient('http://www.macs-software.co.uk/starws/WMSOrderfulfilment.asmx?WSDL');
$response = $client->echo( array('a'=>date('H:i:s')) );
var_dump($response);
Now compare this to the output of
http://www.macs-software.co.uk/starws/W ... mx?op=echo
See how this matches?
I could also use something like
Code: Select all
<?php
class WMSOrderfulfilment_echo {
public $a;
public function __construct($message) {
$this->a = (string)$message;
}
}
$e = new WMSOrderfulfilment_echo( date('H:i:s') );
$client = new SoapClient('http://www.macs-software.co.uk/starws/WMSOrderfulfilment.asmx?WSDL');
$response = $client->echo( $e );
var_dump($response);
Your cancellation request might look like
Code: Select all
<?php
$client = new SoapClient('http://www.macs-software.co.uk/starws/WMSOrderfulfilment.asmx?WSDL');
$response = $client->CancelOrder(array('OrderCancellation'=>array('OrderNumber'=>'SOR01212')));
var_dump($response);
according to
http://www.macs-software.co.uk/starws/W ... ancelOrder you will get an response without any data in it - no way to find out wether an order actually has been canceled or not.
And now the part you won't like. Take a look at
http://www.macs-software.co.uk/starws/W ... PlaceOrder
php5's soap extension doesn't create stubs for all those objects/interfaces (like other languages/frameworks/IDEs do). At least you can have it print the types via print_r($client->__getTypes()).
Posted: Fri Aug 31, 2007 7:18 am
by phpcoder
volka wrote:First please try something simpler
Code: Select all
<?php
$client = new SoapClient('http://www.macs-software.co.uk/starws/WMSOrderfulfilment.asmx?WSDL');
$response = $client->echo( array('a'=>date('H:i:s')) );
var_dump($response);
Now compare this to the output of
http://www.macs-software.co.uk/starws/W ... mx?op=echo
See how this matches?
I could also use something like
Code: Select all
<?php
class WMSOrderfulfilment_echo {
public $a;
public function __construct($message) {
$this->a = (string)$message;
}
}
$e = new WMSOrderfulfilment_echo( date('H:i:s') );
$client = new SoapClient('http://www.macs-software.co.uk/starws/WMSOrderfulfilment.asmx?WSDL');
$response = $client->echo( $e );
var_dump($response);
Your cancellation request might look like
Code: Select all
<?php
$client = new SoapClient('http://www.macs-software.co.uk/starws/WMSOrderfulfilment.asmx?WSDL');
$response = $client->CancelOrder(array('OrderCancellation'=>array('OrderNumber'=>'SOR01212')));
var_dump($response);
according to
http://www.macs-software.co.uk/starws/W ... ancelOrder you will get an response without any data in it - no way to find out wether an order actually has been canceled or not.
And now the part you won't like. Take a look at
http://www.macs-software.co.uk/starws/W ... PlaceOrder
php5's soap extension doesn't create stubs for all those objects/interfaces (like other languages/frameworks/IDEs do). At least you can have it print the types via print_r($client->__getTypes()).
Hi I manged to remove error but now when I try to display response I am getting following error:
Object of class stdClass could not be converted to string
The code that I am using to display response is
Code: Select all
$res = $client->CancelOrder($wrap);
print $res;
Posted: Fri Aug 31, 2007 7:39 am
by mcog_esteban
This is the CancelOrder parameter:
<s:element name="OrderCancellation" type="s1:OrderCancellation"/>
<s:complexType name="OrderCancellation">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="OrderNumber" type="s:string"/>
</s:sequence>
</s:complexType>
Do the same thing for the response value and add the "stubs"
Code: Select all
class OrderCancelation
{
/**
* @var string OrderNumber */
public $OrderNumber;
}
class OrderCancelationResponse
{
/**
* @var string Response */
public $Response;
}
then
Code: Select all
$request = new OrderCancelation();
$request->OrderNumber = 'SOR01212';
$args = array($request);
$response = new OrderCancelationResponse();
$response = $client->$client->__call("CancelOrder", $args);
....
the idea is to create a "stub" for each request/response types on the operations.
Posted: Fri Aug 31, 2007 7:55 am
by volka
phpcoder wrote:Hi I manged to remove error but now when I try to display response I am getting following error:
Object of class stdClass could not be converted to string
That's why I used var_dump().
You get an empty stdClass object as response; no property, no method defined.
Posted: Fri Aug 31, 2007 10:23 am
by phpcoder
mcog_esteban wrote:This is the CancelOrder parameter:
<s:element name="OrderCancellation" type="s1:OrderCancellation"/>
<s:complexType name="OrderCancellation">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="OrderNumber" type="s:string"/>
</s:sequence>
</s:complexType>
Do the same thing for the response value and add the "stubs"
Code: Select all
class OrderCancelation
{
/**
* @var string OrderNumber */
public $OrderNumber;
}
class OrderCancelationResponse
{
/**
* @var string Response */
public $Response;
}
then
Code: Select all
$request = new OrderCancelation();
$request->OrderNumber = 'SOR01212';
$args = array($request);
$response = new OrderCancelationResponse();
$response = $client->$client->__call("CancelOrder", $args);
....
the idea is to create a "stub" for each request/response types on the operations.
My php code is as follows:
Code: Select all
<?php
class OrderCancellation
{
public $OrderNumber;
}
class CancelOrder
{
public $OrderCancellation;
}
class OrderCancelationResponse
{
public $Response;
}
class SoapClientDebug extends SoapClient {
public function __doRequest($request, $location, $action, $version) {
echo '<pre>request: ', htmlentities($request), "\n</pre>\n";
$response = parent::__doRequest($request, $location, $action, $version);
echo '<pre>response: ', htmlentities($response), "\n</pre>\n";
return $response;
}
}
$client = new SoapClientDebug("http://192.168.1.74/starwstest/wmsorderfulfilment.asmx?WSDL");
$ob = new OrderCancellation;
$ob->OrderNumber = '123456';
$wrap = new CancelOrder;
$wrap->OrderCancellation = $ob;
$res = new OrderCancelationResponse();
$res = $client->CancelOrder($wrap);
echo $res->Response;
?>
Is this is the right way I am doing? And also the I am getting empty response i.e I am getting just blank screen. Is there something I am doing wrong or server is replying with empty string?
Response I am getting
Code: Select all
request: <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://uk.co.macs-software.integration.wms.messagetypes/v1.00" xmlns:ns2="http://uk.co.macs-software/WMSOrderFulfilment/"><SOAP-ENV:Body><ns2:CancelOrder><ns1:OrderCancellation><ns1:OrderNumber>123456</ns1:OrderNumber></ns1:OrderCancellation></ns2:CancelOrder></SOAP-ENV:Body></SOAP-ENV:Envelope>
response: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CancelOrderResponse xmlns="http://uk.co.macs-software/WMSOrderFulfilment/" /></soap:Body></soap:Envelope>
Help me please
Posted: Fri Aug 31, 2007 10:28 am
by mcog_esteban
I don't know what you do on the server, but you should return an object type of OrderCancelationResponse.
Code: Select all
........
//On the server
$res = new OrderCancelationResponse();
$res->Response = "something";
return $res;
Posted: Fri Aug 31, 2007 12:04 pm
by volka
If the current wsdl file still is
http://www.macs-software.co.uk/starws/W ... .asmx?WSDL then the response really doesn't carry any payload data.
<s:element name="CancelOrderResponse">
<s:complexType/>
</s:element>
You can see proof of that in the plain xml response string
volka wrote:You get an empty stdClass object as response; no property, no method defined.
Is
http://192.168.1.74/starwstest a test environment for
http://www.macs-software.co.uk/starws/ ? (it certainly looks like it is)
Posted: Mon Sep 03, 2007 6:51 am
by phpcoder
Yep it is. Please could you tell me how to pass parameters(If you can look at my post
Soap Service Parameters
Thnaks