I
I
IdFox2014-05-22 02:48:10
PHP
IdFox, 2014-05-22 02:48:10

How to implement a SOAP request in PHP?

Good afternoon.
I didn’t work closely with SOAP on PHP, so I decided to turn here for advice.
Task. Implement tour search via SOAP request.
Description here - https://www.natalie-tours.ru/webservices_RU/
Compose "one level" of the hierarchy seems to understand how.
That is, for example, the code
<?php
$req_pms = new stdClass();
$req_pms->wsLoginPassword = new stdClass();
$req_pms->wsLoginPassword->wslogin = "MY_LOGIN";
$req_pms->wsLoginPassword->wspassword = "MY_PASSWORD";
$req_data = new SoapVar($req_pms, SOAP_ENC_OBJECT, 'wsLoginPassword', ' www.natalie-tours.ru/webservices ');
$client = new SoapClient(' www.natalie-tours.');
echo '';
print_r($client->getAllAgeTypes($req_data));
?>
All clear. All clear.
And how to implement, for example, the addTourproduct request?
That is, there are different namespaces. Nesting, etc.
That is, you can’t write like that anymore.
$req_pms = new stdClass();
$req_pms->wsLoginPassword = new stdClass();
$req_pms->wsLoginPassword->wslogin = "MY_LOGIN";
$req_pms->wsLoginPassword->wspassword = "MY_PASSWORD";
$req_pms->addToOrderRequest = new stdClass();
$req_pms->addToOrderRequest->orderId = 123;
Thanks in advance for any help.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
Yuri Denisov, 2014-05-22
@denissov

why did you go this way and not like this:

ini_set('soap.wsdl_cache_enabled', '0'); 
  ini_set('soap.wsdl_cache_ttl', '0'); 
    try { 
                // Создание SOAP-клиента
        
                $client = new SoapClient("http://www.natalie-tours.ru/webservice/BookingWS?WSDL");
    $params = array( 
        'wsLoginPassword' => array(
          'wslogin' => "MY_LOGIN",
           'wspassword' => "MY_PASSWORD"
        ));
        
                $request = $client->getAllAgeTypes($params);
    $result = $request->getAllAgeTypes->result;
    echo "$result";
    } 
    catch (SoapFault $exception) 
      {
        echo $exception->getMessage(); 
      }

Then it is easier to organize any level of nesting.

C
ChernovGV, 2015-08-21
@ChernovGV

And how to implement, for example, the addTourproduct request?
That is, there are different namespaces. Nesting, etc.
That is, you can’t write like that anymore.

Why not?
This article explains everything in detail, here is an example:
$req = new Request();
$req->messageList = new MessageList();
$req->messageList->message = new Message();
$req->messageList->message->phone = '79871234567';
$req->messageList->message->text = 'Тестовое сообщение 1';
$req->messageList->message->date = '2013-07-21T15:00:00.26';
$req->messageList->message->type = 15;

$client = new SoapClient(   "http://{$_SERVER['HTTP_HOST']}/smsservice.wsdl.php",
                            array( 'soap_version' => SOAP_1_2));
var_dump($client->sendSms($req));

Those. you just need to collect the necessary object (see the service documentation), and pass it to your method:
Don't worry about the namespace, they are put down automatically based on the WSDL.

M
Marina Smirnova, 2016-07-23
@99WEBDEV

Good afternoon! Did you manage to implement the SOAP request? Could you show a working example, if it's easy, because it doesn't work for my locale. Thank you!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question