0

A third party has given me his webservice document for testing. I try to connect to the soap webservice by passing values to the header and body.

The method I want to consume is ConsultarAfiliado.

the soap structure is :

            POST /WSAutorizaciones/WSAutorizacionLaboratorio.asmx HTTP/1.1
    Host: 191.97.91.43
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "https://arssenasa.gob.do/ConsultarAfiliado"

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
    <AuthenticationHeader xmlns="https://arssenasa.gob.do/">
    <Cedula>string</Cedula>
    <Password>string</Password>
    <Proveedo>int</Proveedo>
    </AuthenticationHeader>
    </soap:Header>
    <soap:Body>
    <ConsultarAfiliado xmlns="https://arssenasa.gob.do/">
    <TipoDocumento>int</TipoDocumento>
    <NumDocumento>string</NumDocumento>
    </ConsultarAfiliado>
    </soap:Body>
    </soap:Envelope>

I tried these codes :

    $wsdl =http://191.97.91.43/WSAutorizaciones/WSAutorizacionLaboratorio.asmx?WSDL";
    $client = new SoapClient($wsdl, array('trace' => 1));  // The trace param will show you errors stack

    $auth =array('Cedula' => '001-0945751-5', 'Password' => 'dmfvmxm2', 'Proveedo' => '12077');
     $header = new SoapHeader('NAMESPACE','AuthenticationHeader',$auth,false);
      var_dump($client->__setSoapHeaders($header));

    // web service input params
    $request_param = array('TipoDocumento' => '2', 'NumDocumento' => '021827151');
    $responce_param = null;
    try {
        $responce_param = $client->ConsultarAfiliado($request_param);

        print_r($responce_param->ConsultarAfiliadoResponse);
    } catch (Exception $e) {
        echo "<h2>Exception Error!</h2>";
        echo $e->getMessage();
    }

I got this error:

Exception Error! Server was unable to process request. ---> Object reference not set to an instance of an object.

May someone please help me fix that out.
Here is the WSDL: http://191.97.91.43/WSAutorizaciones/WSAutorizacionLaboratorio.asmx?WSDL

Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33
Diasline
  • 625
  • 3
  • 32
  • 4
    You should really not post passwords on Stackoverflow. – Blackbam Mar 04 '21 at 16:42
  • thank you but there are fake – Diasline Mar 04 '21 at 16:44
  • According to the error message this might be a duplicate of: https://stackoverflow.com/questions/779091/what-does-object-reference-not-set-to-an-instance-of-an-object-mean – Blackbam Mar 04 '21 at 16:47
  • I see it but cannot figure out where I'm wrong in my codes. Would you please help me out and you would win the 50 points of bounty – Diasline Mar 04 '21 at 17:04
  • please let someone help me with this – Diasline Mar 04 '21 at 22:16
  • Is it a server side error or a problem with your code? Did you try to do the same request in another programming language or with a SOAP tester? The only thing I recognize is that you pass "TipoDocumento" as a string, but an integer is required. – Blackbam Mar 05 '21 at 09:45
  • it's not a server problem because I got the response when I use postman, I changed the TipoDocumento as well still not resolve – Diasline Mar 05 '21 at 13:55
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/229564/discussion-between-diasline-and-blackbam). – Diasline Mar 05 '21 at 14:06
  • What is the var_dump result of the $responce_param after invocation of SoapClient, and BEFORE print_r of its' member? – Daniel Protopopov Mar 07 '21 at 10:29
  • I edited my question by adding the correct values to check it by yourself. I got the response with postman, now I want to use php soap to get the response as well. – Diasline Mar 07 '21 at 20:48
  • It appears to be some kind of custom (or outdated) SOAP service that doesn't want to cooperate with SoapClient or Zend SOAP client. The only way I was able to get it running is through Postman (as you), and am out of options of what you can do here. – Daniel Protopopov Mar 07 '21 at 22:42
  • ok, I see. Many thanks for your attempt to help me. – Diasline Mar 07 '21 at 22:45

2 Answers2

2

Finally I successfully found out the problem of that SOAP header. We know that webservice is old over API, but some websites keep using webservice (WSL) to give response to client.

The only change I made is in the NAMESPACE, just replace it with the url in the AuthenticationHeader:

The mistake:

$header = new SoapHeader('NAMESPACE','AuthenticationHeader',$auth,false);

The correction:

$header = new SoapHeader('https://arssenasa.gob.do/','AuthenticationHeader',$auth,false);
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Diasline
  • 625
  • 3
  • 32
  • 1
    No wonder we missed it as in some cases people use NAMESPACE as template parameter, which should be a [URL namespace](https://stackoverflow.com/questions/13465168/php-namespaces-in-soapheader-child-nodes) – Daniel Protopopov Mar 09 '21 at 10:17
  • you are right man. I hope that someone will accept my answer. – Diasline Mar 09 '21 at 14:01
-1

Ok I saw some problems:

  1. the wsdl variable is missing the opening quote
  2. in the SoapHeader you must set as namespace "https://arssenasa.gob.do/"
  3. you can't directly call `$ client-> ConsultAffiliate ($ request_param)` you have to use `` `__soapCall``` and then specify the name of the caller

I leave you below the code working

$wsdl = "http://191.97.91.43/WSAutorizaciones/WSAutorizacionLaboratorio.asmx?WSDL";
        $client = new SoapClient($wsdl, array('trace' => 1));  // The trace param will show you errors stack

        $auth = array('Cedula' => '001-0945751-5', 'Password' => 'dmfvmxm2', 'Proveedo' => '12077');
//        $header = new SoapHeader('NAMESPACE', 'AuthenticationHeader', $auth, false);
        $header = new SoapHeader('https://arssenasa.gob.do/', 'AuthenticationHeader', $auth, false);
        $client->__setSoapHeaders($header);

        // web service input params
        $request_param = array('TipoDocumento' => '2', 'NumDocumento' => '021827151');
        $responce_param = null;
        try {
            $responce_param = $client->__soapCall('ConsultarAfiliado',$request_param);
//            $responce_param = $client->ConsultarAfiliado($request_param);
            var_dump($responce_param);

        } catch (Exception $e) {
            echo "<h2>Exception Error!</h2>";
            echo $e->getMessage();
        }

Right now the service answers me this, but I don't know if it is the expected answer:

{
  +"ConsultarAfiliadoResult": {#801
    +"Contrato": 0
    +"IdEstado": 0
    +"CodigoFamiliar": 0
    +"IdRegimen": null
    +"Edad": "0"
    +"TipoDocumento": 0
    +"CodigoAfiliado": 0
    +"MensajeAfiliado": """
      System.NullReferenceException: Object reference not set to an instance of an object.
         at SeNaSa.Autorizaciones.Services.AutorizationUtils.DocumentValidations(Int32 TipoDocumento, String NumDocumento)
         at SeNaSa.Autorizaciones.Services.AfiliadoServices.GetAfiliadoInfo(Int32 tipoDocumento, String numDocumento, Int32 Proveedo)
         at WSAutorizaciones.WebService1.ConsultarAfiliado(Int32 TipoDocumento, String NumDocumento)
      """
  }
}
WILLIAM DAZA
  • 118
  • 1
  • 7
  • When test $responce_param = $client->__soapCall('ConsultarAfiliado',$request_param) from my end the values are all 0 or null but when I use $responce_param = $client->ConsultarAfiliado($request_param); I got all the results. – Diasline Mar 09 '21 at 19:17