I’m currently trying to set up a SOAP-server using the following code.
server.php
<?php
class Name {
private $_name;
public function setName($name) {
$this->_name = $name;
}
public function getName() {
return $this->_name;
}
}
$server = new SoapServer('soap.wsdl');
$server->setClass('Name');
$server->handle();
?>
client.php
<?php
$client = new SoapClient('soap.wsdl');
$client->setName('test');
print $client->getName();
?>
soap.wsdl
<?xml version ="1.0" encoding ="UTF-8" ?>
<definitions
name="Name"
targetNamespace="/Name/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="nameInput">
<part name="sName" type="xsd:string" />
</message>
<message name="nameOutput">
<part name="sName" type="xsd:string" />
</message>
<portType name="NamePortType">
<operation name="setName" parameterOrder="sName">
<input message="tns:nameInput" />
</operation>
<operation name="getName">
<output message="tns:nameOutput" />
</operation>
</portType>
<binding name="NameBinding" type="tns:NamePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="setName">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
</operation>
<operation name="getName">
<soap:operation soapAction=""/>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="NameService">
<port name="NamePort" binding="tns:NameBinding">
<soap:address location="http://10.200.3.48/zI/soap/server.php"/>
</port>
</service>
</definitions>
Is it possible to store a value in the argument of the class object? getName() returns an empty string.
No It is not possible to store the value in WebService.
When you call the webservice, Server create separate thread with new instance of class and the values you stored are got vanish.