SOAP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Earis
Forum Newbie
Posts: 2
Joined: Wed Dec 03, 2008 3:31 pm

SOAP

Post by Earis »

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:

Code: Select all

 
$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:

Code: Select all

 
$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

Code: Select all

 
<?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.
Earis
Forum Newbie
Posts: 2
Joined: Wed Dec 03, 2008 3:31 pm

Re: SOAP

Post by Earis »

Hey, isn't there anybody who knows SOAP?
I really need help :banghead:
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Re: SOAP

Post by dude81 »

I've not played with soapServer Yet, but seeing your problem dont you think

Code: Select all

$server->setClass("Class1");
sets one class at a time..... I doubt this could be a problem
Post Reply