How to get response from a SOAP request using zend-soap?

562 Views Asked by At

I've been spending sometime with problem. I have a endpoint I want to send some data and receive a response.

I've look online and I've seen that Zend\Soap\Server is used to build methods, and Zend\Soap\Client can than use those methods. I would like for someone to explain what to write in those methods, and how that helps with getting a response.

$client = new Client($this->wsdl, array('soap_version' => SOAP_1_1));

Now we can $client->SOMEMETHOD();

My questions are: 'Where do I get this method from?', 'what will method do?', and 'how do I use it?'

2

There are 2 best solutions below

0
Eric On

SOAP short base

SOAP allows to request an online service. (use as a client code) for example you can query AMAZON on a product, know its price, etc.

SOAP works in 2 different ways:

way 1: wdsl mode

when you create a connection to a SOAP client, you must provide a link that will provide an XML file: the wdsl

example: type in your browser: http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl

congratulation : you see (discover) the way to query AMAZON !

this XML file tells you what you can ask for: a price, a product info, a search, etc ..: these are the routes.

for each route (each possible query) the parameters you must provide, the validity check of these parameters: example: route = search article, param1 = article name, type of parameter = string, etc...

$client = new Client($this->wsdl, array( 'soap_version' => SOAP_1_1 ) )

create a client object :
$this->wsdl a link to xml file (the discovery part)
it's a URI string : example : "http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl"

array( 'soap_version' => SOAP_1_1 ) = i use SOAP version xx, you can add more options in this array.

way 2: non wdsl mode

you do not provide a wsdl link or file... but you must know how to handle request and responses

deep learning

search on google a tutorial for SOAP, there are online requester for test purpose, etc... then use it in zend

0
Gerald Ibra On

I solved my problem, so I'll post it here for anyone to understand.

$client = new Client($wsdl, ['soap_version' => SOAP_1_1]);

$params = [
   'args0' =>  [ 
      '_PRCODASSOC' => null, 
      '_PRCODDELEG' => null, 
      '_PRCODFISCALE' => 'BRSLSN312213TY', 
      '_PRCODFSDDIRI' => null,
      '_PRTIPOOPERAWS' => 'REPFAM' 
    ]
];

$client->ws_fam_sgf($params); 
$result = $client->getLastResponse(); 
die($result); 

All I did was add 'args' => [] and added all my parameters inside that key.