SOAP Client PHP

Hello!

Until now, I didn't have to send parameters over SOAP. Now there is a need to form such a parameter structure:

<wsLoginPassword xsi:type="java:WsLoginPassword" xmlns:java="java:com.nt.slib.ws.wssearch">
<wslogin xsi:type="xsd:string">YOUR_LOGIN</wslogin>
<wspassword xsi:type="xsd:string">your_password</wspassword>
</wsLoginPassword>

I do this:

$params = array(
new SoapVar('login', 'wslogin'), 
new SoapVar('123', 'wspassword')
);
$var = new SoapVar(Array('wsLoginPassword' => $params), SOAP_ENC_OBJECT, 'wsLoginPassword', 'http://www.natalie-tours.ru/webservices');
$client = new SoapClient('http://www.natalie-tours.ru/webservice/BookingWS?WSDL', array('trace' => 1));
$client->getAllRegions($var);

After execution, it writes that the username is not correct. I assume that the request is a curve. Please tell me which way to dig?

 1
Author: Глеб Глебов, 2013-08-12

1 answers

Better late than never, I've been dealing with this myself for a long time, maybe someone else will help.

I would implement it a little differently (at least where I write Soap requests I do it like this). For the variables that will be used to form the soap request hml, we make classes. We look in the wsdl(I climbed the link that you gave in the code), first we call the operation for the client:

<operation name="getAllRegions">
   <input message="tns:getAllRegions"></input>
   <output message="tns:getAllRegionsResponse"></output>
</operation>

We see that here a variable of the getAllRegions type is accepted as input, this can be done view in the message description

<message name="getAllRegions">
  <part name="parameters" element="partns:getAllRegions"></part>
</message>

Looking for where it is described:

<xsd:element name="getAllRegions">
 <xsd:complexType>
   <xsd:sequence>
     <xsd:element type="tp:WsLoginPassword" name="wsLoginPassword></xsd:element>
     </xsd:sequence>
   </xsd:complexType>

Yeah, if so, then we still need to describe the WsLoginPassword that it consists of:

<xsd:complexType name="WsLoginPassword">
 <xsd:sequence>
  <xsd:element type="xsd:string" name="wslogin" minOccurs="1" maxOccurs="1" nillable="true"></xsd:element>
  <xsd:element type="xsd:string" name="wspassword" minOccurs="1" maxOccurs="1" nillable="true"></xsd:element>
 </xsd:sequence>
</xsd:complexType>

Well, let's go:

class getAllRegions{
  public $WsLoginPassword
}

class WsLoginPassword{
  public $wslogin;
  public $wspassword;
}

try{
$requestClass = new getAllRegions();
$requestClass->WsLoginPassword = new WsLoginPassword();
$requestClass->WsLoginPassword->wslogin = 'login';
$requestClass->WsLoginPassword->wspassword = '123';
$client = new SoapClient('http://www.natalie-tours.ru/webservice/BookingWS?WSDL', 
                                 [
                                     'trace' => true,
                                     'exceptions'=>true
                                 ]);
$client->getAllRegions($requestClass);
}catch (SoapFault $e){
  //тут из клиента во время дебага можно посмотреть или
  // через echo настроить вывод содержимого. В 
  // $client->__getLastResponse() содержится что тебе ответил сервис,
  // а в $client->__getLastRequest() какую xml клиент отправит на сервак
  // после обработки классов выше. В $e будет текст ошибки.
}
 1
Author: Mikhail, 2017-10-05 11:25:08