null return in soap function with object (para/ret)called
Posted: Tue Jul 24, 2007 7:59 am
feyd | Please use
The function to be called consists of three php files
Employee.class.php[/syntax]
Salary.class.php
ProcessEmployee.php
employeeclient.php
when the client is called only NULL value is returned
Can anybody help me with these.
i am fairly new in using object oriented PHP and Soap. Any help will be appreciated.
Thanks in advance
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Friends,
i need to develop a simple web service using soap which gets Employee name and Basic Salary and returns name,basic salary and Hra.
For that i used the following wsdl file:
[b]ProcessEmployee.wsdl[/b]
[syntax="xml"]<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://sybrant.com" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://sybrant.com" xmlns:intf="http://sybrant.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.3
Built on Oct 05, 2005 (05:23:37 EDT)-->
<wsdl:types>
<schema targetNamespace="http://sybrant.com" xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="Employee">
<sequence>
<element name="basic" type="xsd:int"/>
<element name="name" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="Salary">
<sequence>
<element name="basic" type="xsd:int"/>
<element name="hra" type="xsd:int"/>
<element name="name" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
</schema>
</wsdl:types>
<wsdl:message name="calculateSalaryResponse">
<wsdl:part name="calculateSalaryReturn" type="impl:Salary"/>
</wsdl:message>
<wsdl:message name="calculateSalaryRequest">
<wsdl:part name="employee" type="impl:Employee"/>
</wsdl:message>
<wsdl:portType name="ProcessEmployee">
<wsdl:operation name="calculateSalary" parameterOrder="employee">
<wsdl:input message="impl:calculateSalaryRequest" name="calculateSalaryRequest"/>
<wsdl:output message="impl:calculateSalaryResponse" name="calculateSalaryResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ProcessEmployeeSoapBinding" type="impl:ProcessEmployee">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="calculateSalary">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="calculateSalaryRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://sybrant.com" use="encoded"/>
</wsdl:input>
<wsdl:output name="calculateSalaryResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://sybrant.com" use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ProcessEmployeeService">
<wsdl:port binding="impl:ProcessEmployeeSoapBinding" name="ProcessEmployee">
<wsdlsoap:address location="http://192.168.1.128:80/soap/ProcessEmployee.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>The function to be called consists of three php files
Employee.class.php[/syntax]
Code: Select all
<?
class Employee
{
public $name;
public $basic;
function setName($name)
{
$this->name=$name;
}
function getName()
{
return $this->name;
}
function setBasic($basic)
{
$this->basic=$basic;
}
function getBasic()
{
return $this->basic;
}
}
?>Code: Select all
<?
class Salary {
public $name;
public $basic;
public $hra;
function setBasic($tempbasic)
{
$this->basic=$tempbasic;
}
function getBasic()
{
return $this->basic;
}
function setHra($temphra)
{
$this->hra=$temphra;
}
function getHra()
{
return $this->hra;
}
function getName()
{
return $this->name;
}
function setName($name)
{
$this->name=$name;
}
}
?>Code: Select all
<?
include 'Employee.class.php';
include 'Salary.class.php';
class ProcessEmployee
{
private $empname;
private $basic;
public function calculateSalary(Employee $employee)
{
settype($emp,"Employee");
$emp=$employee;
if($emp instanceof Employee)
{
$empname = $emp->getName();
$basic = $emp->getBasic();
//$empname = $emp->getBasic();
//$basic = $emp->getName();
}
else {
print "Error: Passed wrong kind of object";
}
$sal=new Salary();
$sal->setBasic((int)($this->basic));
$sal->setHra((int)($this->basic * 0.1));
$sal->setName((string)($this->empname));
return $sal;
}
}
ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer("ProcessEmployee.wsdl");
$server->setClass("ProcessEmployee");
$server->handle();
?>employeeclient.php
Code: Select all
include "Employee.class.php";
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
try {
$client = new SoapClient("http://192.168.1.128/soap/ProcessEmployee.php?wsdl");
$testobj=new Employee;
$testobj->setName('Rajula');
$testobj->setBasic(1000);
$response = $client->calculateSalary($testobj);
$simpleresult=$response->calculateSalaryResult;
var_dump($response);
} catch (SoapFault $exception) {
echo $exception;
}
?>when the client is called only NULL value is returned
Can anybody help me with these.
i am fairly new in using object oriented PHP and Soap. Any help will be appreciated.
Thanks in advance
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]