Hi. I've got 2 classes that provide services and 1 wsdl file for both of them, 1 SoapServer and 1 SoapClient.
When I do

$server->setClass("Class1");
$server->handle();

I can call functions from Class1 in the SoapClient. But if I do

$server->setClass("Class1");
$server->setClass("Class2");
$server->handle();

then I am able only to call the functions from Class2, the ones from Class1 disappear.
I suppose the problem can be solved if I correctly use namespaces, but don't know how.

Here's the php file for the server - server.php:

$server = new SoapServer("bla.wsdl");

$server->setClass("Class1");
$server->setClass("Class2");

$server->handle();


class Class1 {
   public function pow2($a) { return $a * $a; }
   public function pow3($a) { return $a * $a * $a; }
}

class Class2 {
   public function pow4($a) { return $a * $a * $a * $a; }
}

client.php:

$client = new SoapClient("bla.wsdl");

echo "2 ^ 2 = " . $client->pow2(2) . "\n";
echo "2 ^ 3 = " . $client->pow3(2) . "\n";
echo "2 ^ 4 = " . $client->pow4(2) . "\n";

and the wsdl file - bla.wsdl

<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions
 xmlns:class1Ns='http://example.org/Class1'
 xmlns:class2Ns='http://example.org/Class2'
 xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
 xmlns:xsd='http://www.w3.org/2001/XMLSchema'
 xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
 xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
 xmlns='http://schemas.xmlsoap.org/wsdl/'>

<message name='pow2Request'>
 <part name='number' type='xsd:float'/>
</message>

<message name='pow2Response'>
 <part name='result' type='xsd:float'/>
</message>

<message name='pow3Request'>
 <part name='number' type='xsd:float'/>
</message>

<message name='pow3Response'>
 <part name='result' type='xsd:float'/>
</message>

<message name='pow4Request'>
 <part name='number' type='xsd:float'/>
</message>

<message name='pow4Response'>
 <part name='result' type='xsd:float'/>
</message>




<portType name='Class1PortType'>
 <operation name='pow2'>
  <input message='class1Ns:pow2Request'/>
  <output message='class1Ns:pow2Response'/>
 </operation>
 <operation name='pow3'>
  <input message='class1Ns:pow3Request'/>
  <output message='class1Ns:pow3Response'/>
 </operation>
</portType>

<portType name='Class2PortType'>
 <operation name='pow4'>
  <input message='class2Ns:pow4Request'/>
  <output message='class2Ns:pow4Response'/>
 </operation>
</portType>




<binding name='Class1Binding' type='class1Ns:Class1PortType'>

 <soap:binding style='rpc'
  transport='http://schemas.xmlsoap.org/soap/http'/>
 
 <operation name='pow2'>
  <soap:operation soapAction='urn:pow2'/>
  <input>
   <soap:body use='literal'/>
  </input>
  <output>
   <soap:body use='literal'/>
  </output>
 </operation>
 
 <operation name='pow3'>
  <soap:operation soapAction='urn:pow3'/>
  <input>
   <soap:body use='literal'/>
  </input>
  <output>
   <soap:body use='literal'/>
  </output>
 </operation>
 
</binding>



<binding name='Class2Binding' type='class2Ns:Class2PortType'>

 <soap:binding style='rpc'
  transport='http://schemas.xmlsoap.org/soap/http'/>
 
 <operation name='pow4'>
  <soap:operation soapAction='urn:pow4'/>
  <input>
   <soap:body use='literal'/>
  </input>
  <output>
   <soap:body use='literal'/>
  </output>
 </operation>
 
</binding>



<service name='Class1AndClass2Service'>
 <port name='Class1Port' binding='class1Ns:Class1Binding'>
  <soap:address location='http://localhost/collision/server.php'/>
 </port>
 
  <port name='Class2Port' binding='class2Ns:Class2Binding'>
  <soap:address location='http://localhost/collision/server.php'/>
 </port>
</service>
</definitions>

If you comment the

$server->setClass("Class2");

line in server.php the first two calls in the client:

echo "2 ^ 2 = " . $client->pow2(2) . "\n";
echo "2 ^ 3 = " . $client->pow3(2) . "\n";

will work.


I've read loads of tutorials and documentation, but couldn't find any solution. So PLEASE help me with this.

try this code
$server->addFunction('function1');
$server->addFunction('function2');
$server->handle();

and to functions or 3 must exist in the wsdl file

This article has been dead for over six months. Start a new discussion instead.