V
V
Vanes Ri_Lax2020-12-29 18:31:42
PHP
Vanes Ri_Lax, 2020-12-29 18:31:42

Why is the SOAP request not working?

Good afternoon, make a SOAP request,
Here is the address of the service
The documentation says the following:
1.2 Synchronous messaging service
The synchronous messaging service provides 1 method:
1. GetMessage - a method for receiving a
message
receiving an XML message in accordance with the schema defined for a particular service.
The method signature is as follows:
GetMessageResponse GetMessage(GetMessageRequest request) , where
GetMessageRequest is a request containing a single Message element, a message that allows you to contain any xml with a mandatory schema specification. For example,

<tns:AuthRequest xmlns:tns="urn://x-artefacts-gnivc-ru/ais3/kkt/AuthService/types/1.0">
  <tns:AuthAppInfo>
    <tns:MasterToken>MASTER_TOKEN_ISSUED_BY_FNS</tns:MasterToken>
  </tns:AuthAppInfo>
</tns:AuthRequest>

GetMessageResponse - a response containing a single Message element - a message that allows you to contain any xml with a mandatory schema specification. For example,
<tns:AuthResponse xmlns:tns="urn://x-artefacts-gnivc-ru/ais3/kkt/AuthService/types/1.0" >
  <tns:Result>
    <tns:Token>TEMPORARY_TOKEN_ISSUED_BY_FNS</tns:Token>
    <tns:ExpireTime>2001-12-17T09:30:47Z</tns:ExpireTime>
  </tns:Result>
</tns:AuthResponse>

I wrote a simple request code in PHP:
try{
        $options = array(
        'soap_version' => SOAP_1_1,
        'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
        'encoding' => 'UTF-8',
        'trace' => 1,
        'exceptions' => true,
        'cache_wsdl' => WSDL_CACHE_NONE,
        'features' => SOAP_SINGLE_ELEMENT_ARRAYS
    );
        $service_Url = 'https://openapi.nalog.ru:8090/open-api/AuthService/0.1?wsdl';
        $SoapClient = new SoapClient($service_Url, $options);

        $daraArray = array('Message' => '

            <AuthRequest xmlns="urn://x-artefacts-gnivc-ru/ais3/kkt/AuthService/types/1.0" xsi:schemaLocation="urn://x-artefacts-gnivc-ru/ais3/kkt/AuthService/types/1.0 schema.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <AuthAppInfo>
                    <MasterToken>'.$modx->getOption('MASTER_TOKEN_ISSUED_BY_FNS').'</MasterToken>
                </AuthAppInfo>
            </AuthRequest>
        ');
        
        $result = $SoapClient->GetMessage($daraArray);
    }catch(Exception $e){
        echo($e);
    }

As a result, I get the answer:

SoapFault exception: [soap:Client] Unmarshalling Error: cvc-complex-type.2.4.b: The content of element 'ns1:Message' is not complete. One of '{WC[##other:"urn://x-artefacts-gnivc-ru/inplat/servin/OpenApiMessageConsumerService/types/1.0"]}' is expected.  in

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
Hanneman, 2020-12-30
@Hanneman

Well, the fact is that you have something tricky with the namespace or missing a component of the request body:
Try to do this: either print the entire text of the SOAP request, or intercept the packets using, for example, Wireshark or smsniff. The work request should look something like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="urn://x-artefacts-gnivc-ru/inplat/servin/OpenApiMessageConsumerService/types/1.0">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:GetMessageRequest>
         <ns:Message>
            <AuthRequest xsi:schemaLocation="urn://x-artefacts-gnivc-ru/ais3/kkt/AuthService/types/1.0 schema.xsd" xmlns="urn://x-artefacts-gnivc-ru/ais3/kkt/AuthService/types/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
               <AuthAppInfo>
                  <MasterToken>eyJhbGciOiJIUzI1NiIsInR5cCI6...</MasterToken>
               </AuthAppInfo>
            </AuthRequest>
         </ns:Message>
      </ns:GetMessageRequest>
   </soapenv:Body>
</soapenv:Envelope>

Answer (because not from Russia):
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>Доступ к сервису для переданного IP, запрещён</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

Here's what I'm talking about: if yours is empty, as in the example (or the namespace of something is not there), then when requesting the form
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="urn://x-artefacts-gnivc-ru/inplat/servin/OpenApiMessageConsumerService/types/1.0">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:GetMessageRequest>
         <ns:Message>
            <!--You may enter ANY elements at this point-->
         </ns:Message>
      </ns:GetMessageRequest>
   </soapenv:Body>
</soapenv:Envelope>

Then you will get the answer, as in your example:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Client</faultcode>
         <faultstring>Unmarshalling Error: cvc-complex-type.2.4.b: The content of element 'ns:Message' is not complete. One of '{WC[##other:"urn://x-artefacts-gnivc-ru/inplat/servin/OpenApiMessageConsumerService/types/1.0"]}' is expected.</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

I
Ilya Chubarov, 2021-11-02
@agoalofalife

Maybe I can save you time with this library
Everything you need is already implemented there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question