SOAP related problem

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
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

SOAP related problem

Post by mcog_esteban »

This is some code i've been testing:
Server.php

Code: Select all

<?php

class Modalidade 
{
	public $Nome;
	public $PeriodoTempo;
	public $Quantidade;
	public $Valor;
	
	function __construct($n, $p, $q, $v)
	{
		$this->Nome = $n;
		$this->PeriodoTempo = $p;
		$this->Quantidade = $q;
		$this->Valor = $v;
	}
	
}

function Destaque($param)
{

$PerfilBW = "PerfilBW";
$PerfilCreditoSegundos = "PerfilCreditoSegundos";
$PerfilIcon = "PerfilIcon";
$PerfilId = 1;
$PerfilLimiteTempoDias = "PerfilLimiteTempoDias";
$PerfilNome = "PerfilNome";
$PerfilObs = "PerfilObs";
$PerfilPreco = "PerfilPreco";
$PerfilTipoPacote = "PerfilTipoPacote";
$Sucesso = 1;

$modalidade1 = new Modalidade('XXX', 'XXX', 'XXX', 'XXX');
$modalidade2 = new Modalidade('AAA', 'AAA', 'AAA', 'AAA');

$modalidades[] = $modalidade1;
$modalidades[] = $modalidade2;

return array('perfilBW' => $PerfilBW,
							'perfilCreditoSegundos' => $PerfilCreditoSegundos,
							'perfilIcon' => $PerfilIcon,
							'perfilId' => $PerfilId,
							'perfilLimiteTempoDias' => $PerfilLimiteTempoDias,
							'perfilNome' => $PerfilNome,
							'perfilObs' => $PerfilObs,
							'perfilPreco' => $PerfilPreço,
							'perfilTipoPacote' => $PerfilTipoPacote,
							'sucesso' => $Sucesso,
							'modalidades' => $modalidades);							
}

?>
index.php (the server it self)

Code: Select all

<?php

include "server.php";

$server = new SoapServer('http://localhost/interacesso/WSInteracesso.wsdl');
      
$server->addFunction('Destaque'); 
$server->handle();

?>
Client.php

Code: Select all

<?php

$client = new SoapClient('WSInteracesso.wsdl');

echo "<pre>";
var_dump($client->__getFunctions());
echo "<pre/>";

echo "<pre>";
var_dump($client->__getTypes());
echo "<pre/>";

$args = array('param' => 1);
echo "<pre>";
var_dump($client->__soapCall('Destaque', $args));
echo "<pre/>";
?>
and this is error i'm getting afer calling the client:

Code: Select all

Fatal error:  Uncaught SoapFault exception: [SOAP-ENV:Server] SOAP-ERROR: Encoding: object hasn't 'Modalidades' property in C:\xampp\htdocs\interacesso\client.php:15
Stack trace:
#0 C:\xampp\htdocs\interacesso\client.php(15): SoapClient->__soapCall('Destaque', Array)
#1 {main}
  thrown in C:\xampp\htdocs\interacesso\client.php on line 15
Sorry forget to include the wsdl file:

Code: Select all

<?xml version="1.0"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" 
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" 
xmlns:tns="urn:WSInteracesso"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:s="http://www.w3.org/2001/XMLSchema" 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
targetNamespace="urn:WSInteracesso" name="WSInteracesso">

	<wsdl:types>
		<s:schema targetNamespace="urn:WSInteracesso"
		xmlns:s="http://www.w3.org/2001/XMLSchema" 
		xmlns:tns="urn:WSInteracesso" 
		elementFormDefault="qualified">
		
			<s:element name="DestaquePedido" type="s:int"/>
			<s:element name="DestaqueResposta">
				<s:complexType>
					<s:sequence>
						<s:element name="Modalidades" type="tns:ArrModalidades" maxOccurs="1"/>
						<s:element name="PerfilBW" type="s:string" maxOccurs="1"/>
						<s:element name="PerfilCreditoSegundos" type="s:string" maxOccurs="1"/>
						<s:element name="PerfilIcon" type="s:string" maxOccurs="1"/>
						<s:element name="PerfilId" type="s:int" maxOccurs="1"/>
						<s:element name="PerfilLimiteTempoDias" type="s:string" maxOccurs="1"/>
						<s:element name="PerfilNome" type="s:string" maxOccurs="1"/>
						<s:element name="PerfilObs" type="s:string" maxOccurs="1"/>
						<s:element name="PerfilPreco" type="s:string" maxOccurs="1"/>
						<s:element name="PerfilTipoPacote" type="s:string" maxOccurs="1"/>
						<s:element name="Sucesso" type="s:int" maxOccurs="1"/>
					</s:sequence>
				</s:complexType>
			</s:element>
			<s:element name="ArrModalidades" type="tns:ArrModalidades"/>
			<s:complexType name="ArrModalidades">
				<s:sequence>
					<s:element name="Modalidade" type="tns:Modalidade" minOccurs="0" maxOccurs="unbounded"/>
				</s:sequence>
			</s:complexType>
			<s:element name="Modalidade" type="tns:Modalidade"/>
			<s:complexType name="Modalidade">
				<s:sequence>
					<s:element name="Nome" type="s:string" maxOccurs="1"/>
					<s:element name="PeriodoTempo" type="s:string" maxOccurs="1"/>
					<s:element name="Quantidade" type="s:string" maxOccurs="1"/>
					<s:element name="Valor" type="s:string" maxOccurs="1"/>
				</s:sequence>
			</s:complexType>
		</s:schema>
	</wsdl:types>
	<wsdl:message name="DestaqueSoapIn">
		<wsdl:part name="pDestaquePedido" element="tns:DestaquePedido"/>
	</wsdl:message>
	<wsdl:message name="DestaqueSoapOut">
		<wsdl:part name="parameters" element="tns:DestaqueResposta"/>
	</wsdl:message>
	<wsdl:portType name="WSInteracessoSoap">
		<wsdl:operation name="Destaque">
			<wsdl:input name="Request" message="tns:DestaqueSoapIn"/>
			<wsdl:output name="Response" message="tns:DestaqueSoapOut"/>
		</wsdl:operation>
	</wsdl:portType>
	<wsdl:binding name="WSInteracessoSoapBind" type="tns:WSInteracessoSoap">
		<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
		<wsdl:operation name="Destaque">
			<soap:operation style="document"/>
			<wsdl:input>
				<soap:body use="literal"/>
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal"/>
			</wsdl:output>
		</wsdl:operation>
	</wsdl:binding>
	<wsdl:service name="WSInteracesso">
		<wsdl:port name="WSInteracessoSoapPort" binding="tns:WSInteracessoSoapBind">
			<soap:address location="http://localhost/interacesso"/>
		</wsdl:port>
	</wsdl:service>
</wsdl:definitions>
what seems to be the mistake?
thanks.
Last edited by mcog_esteban on Mon Oct 30, 2006 6:56 am, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

A parameter of the type Modalidades seems to be mandatory. $args, and therefore the call of Destaque, does not contain such a parameter.
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

Post by mcog_esteban »

but the function requires a int parameter, not a Modalidades type parameter.
i thought i forgoted the param, but i send it.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

sorry, I'm blind.
mcog_esteban wrote:Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Server] SOAP-ERROR: Encoding: object hasn't 'Modalidades' property
It's an exception thrown by the server-side part.
mcog_esteban wrote:<s:element name="Modalidades" type="tns:ArrModalidades" maxOccurs="1"/>
[...]
'modalidades' => $modalidades
All names are case-sensitive.
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

Post by mcog_esteban »

Thank you very much Volka.
it worked perfectly.
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

Post by mcog_esteban »

Just a side note.
for every type defined in the WSDL, do i have to create a class of that type in PHP too?
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

Post by mcog_esteban »

Hey Volka, maybe you can help me again.
Just added another type called Cliente, related messages, port type and bindings and created the class Cliente in the server.
When i call the new methiod i got :

Code: Select all

Fatal error:  Uncaught SoapFault exception: [SOAP-ENV:Server] Procedure 'Cliente' not present in C:\xampp\htdocs\interacesso\client.php:41
Stack trace:
#0 [internal function]: SoapClient->__call('insereUser', Array)
#1 C:\xampp\htdocs\interacesso\client.php(41): SoapClient->insereUser(Object(Cliente))
how come it's complaining about a procedure when Cliente is a type?
thanks.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

hm, and what exactly did you change/add?
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

Post by mcog_esteban »

Hi, just got it.
i was using wsdl cache enable.
Post Reply