C
C
cajka-d2021-09-19 16:28:26
PHP
cajka-d, 2021-09-19 16:28:26

What does the error that the SOAP client displays mean?

Hello.

Unable to get data from SOAP server.

Throws an error:
Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object has no 'Type' property


Client code:

<?php
$client = new SoapClient(
      'http://89.208.141.8/CargoMSK/ws/Cargo3WS.1cws?wsdl',
            array(
                'login' => "web",         // логин
                'password' => "web",  // пароль
            )
        );

$a = array(
  'login' => 'login',
  'password' => 'password',
  'documents' => array(
    'Key' => 'Documents',
    'Properties' => array(
      'Key' => 'DocumentType',
      'Value ' => 'Order',
      'ValueType' => 'string',
    ),
    'List' => array(
      array('Key' => '00-00000497004')
    )
  ),
  'parameters' => array(
    'Key' => 'Parameters',
  )
);

$d = $client->Tracking($a);

print_r($d);
?>


Perhaps someone can tell me what I'm doing wrong.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-09-19
@cajka-d

Read wsdl. We find the required request.

operation tracking
<operation name="Tracking">
  <input message="tns:TrackingRequestMessage"/>
  <output message="tns:TrackingResponseMessage"/>
</operation>

This means that the Tracking request takes TrackingRequestMessage as input. Looking further
messageTrackingRequestMessage
<message name="TrackingRequestMessage">
  <part name="parameters" element="tns:Tracking"/>
</message>

The only parameters field with Tracking type. We are looking for this type.
element Tracking
<xs:element name="Tracking">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="Language" type="xs:string" nillable="true"/>
      <xs:element name="Login" type="xs:string" nillable="true"/>
      <xs:element name="Password" type="xs:string" nillable="true"/>
      <xs:element name="Type" type="xs:string"/>
      <xs:element name="Documents" type="xs:string" nillable="true"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

We get an object or an associative array with text fields Language, Login, Password, Type and Documents, and all fields except Type can be null.
So the request should look like
$result = $client->Tracking([
    'Language' => ?string,
    'Login' => ?string,
    'Password' => ?string,
    'Type' => string,
    'Documents' => ?string
]);

The same can be obtained using PHP. After connecting to the client, we get a list of methods.
var_dump($client->__getFunctions());
/* ...
[92] => string(47) "TrackingResponse Tracking(Tracking $parameters)"
... */

This means that the Tracking method takes one parameter with the Tracking type and returns a TrackingResponse type response.
Let's ask for types.
var_dump($client->__getTypes());
Request result
/* ...
[120] => string(103) "struct Tracking {
 string Language;
 string Login;
 string Password;
 string Type;
 string Documents;
}"
[121] => string(51) "struct TrackingResponse {
 ResultTracking return;
}"
[24] => string(81) "struct ResultTracking {
 TrackingInfo Items;
 boolean Error;
 string ErrorInfo;
}"
[28] => string(227) "struct TrackingInfo {
 boolean Error;
 string Type;
 string Number;
 string Info;
 string AgentURL;
 dateTime CreateDate;
 string State;
 dateTime DeliveryDate;
 string DeliveryInfo;
 TrackingEvent History;
 Waybill Waybills;
}"
[27] => string(83) "struct TrackingEvent {
 dateTime EventDate;
 string EventName;
 string EventInfo;
}"
[31] => string(546) "struct Waybill {
 string Type;
 string Number;
 dateTime CreateDate;
 string State;
 dateTime DeliveryDate;
 string Sender;
 string SenderGeography;
 string Recipient;
 string RecipientGeography;
 string RecipientAddress;
 dateTime SendDate;
 string Payer;
 int CargoQty;
 float NetWeight;
 float GrossWeight;
 string ConsolidationNumber;
 string InventoryWaybillNumber;
 string DeliveryMethod;
 float Volume;
 boolean RequirePaymentInCash;
 float PaymentInCash;
 string PaymentInCashCurrency;
 string RecipientOfficial;
 TrackingEvent History;
}"
... */


The only difference from wsdl's self-parsing is that it doesn't specify which fields are optional, which fields can be filled with null, and whether some fields are arrays.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question