0

in one of my projects i need to send SOAP request to remote servers. For doing so i am using below script (using CURL). For some reason i am not getting any response if i ran below script.

If i try sending requests via SOAP UI, all works just like it should be. When replicating functionality in php, i get no response at all and not able to identify what the problem is.

public function sendRequestAction ($cntiin) {

        $userid = 'XXXXX';
        $clientid = 'YYYYY';
        $password = 'Test_Test';
        $urltest = 'https://y.fake.url/testServices/PersonDetailsImplService';

        //variable defenition
        $identifier = '700521700054';

        $xml_post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:data="http://data.fake.url.test.net">
                                <soapenv:Header>
                                <userId>3d4f80d7</userId>
                                </soapenv:Header>
                                <soapenv:Body>
                                <data:getPerson>
                                    <!--Optional:-->
                                    <iin>' . $identifier . '</iin>
                                    <!--Optional:-->
                                    <consentConfirmed>true</consentConfirmed>
                                </data:getPerson>
                                </soapenv:Body>
                            </soapenv:Envelope>';
        $headers = array(
                        "Content-type: text/xml;charset=\"utf-8\"",
                        "Accept: text/xml",
                        "Cache-Control: no-cache",
                        "Pragma: no-cache",
                        "SOAPAction: https://y.fake.url/gbdServices/PersonDetailsImplService", 
                        "Content-length: ".strlen($xml_post_string),
                        ); //SOAPAction: your op URL
        // PHP cURL  for https connection with auth
        $url = $urltest .'?wsdl';
        $ch = curl_init();
        //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_USERPWD, $clientid.":".$password); // username and password - declared at the top of the doc
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        $response = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        print_r($response);
    }

When sending requests via SOAP UI there is Basic Auth with login and password, which i believe is accounted for above. Still no results

I went thruogh numerous articles including: this one and this one and many others but still not sure why not working, so any feedback will be highly appriciated.

Sky21.86
  • 467
  • 1
  • 7
  • 19
  • 1
    Why not use the [Soap Extension](http://php.net/Soap) ? – Jonnix Jan 03 '19 at 08:49
  • Hello @JonStirling, which one would you recommend? – Sky21.86 Jan 03 '19 at 08:54
  • The PHP one that I linked to? – Jonnix Jan 03 '19 at 08:54
  • Just tried initials of it. What i get is when calling $soapClient = new \SoapClient("https://y.fake.url/testServices/PersonDetailsImplService?wsdl") i get error Error: SOAP-ERROR: Parsing WSDL: Couldn't load from "https://y.fake.url/testServices/PersonDetailsImplService?wsdl". And i am not sure what the resason for this may be – Sky21.86 Jan 03 '19 at 09:02
  • Can PHP access the WSDL file you've sent it to from where you're running it? Does it give back a valid WSDL document? Etc. – Jonnix Jan 03 '19 at 09:08
  • That i am not totally sure. All is working through SOAUP UI and browser. How can i check it? – Sky21.86 Jan 03 '19 at 09:25
  • I don't know since I don't have access to your environments to check. Another thing to check is that you've passed your basic auto credentials into SoapClient appropriately. – Jonnix Jan 03 '19 at 09:29
  • If i use $soapClient = new \SoapClient("https://soapserver.example.com/blahblah.asmx?wsdl"); - i get the error already at this stage (before i make the actual call to server). Do i maybe need to pass some augh details when defining client already? – Sky21.86 Jan 03 '19 at 09:37
  • Yes you do. See the docs (well hidden) at http://php.net/manual/en/soapclient.soapclient.php – Jonnix Jan 03 '19 at 09:39
  • Using the same logic as under link above i get $client = new \SoapClient('https://y.fake.url/testServices/PersonDetailsImplService?wsdl', array( 'login' => "YYYY", 'password' => "XXXX" ) ); -- this one yields the same error code "Error: SOAP-ERROR: Parsing WSDL: Couldn't load from". Using same url, login and password in the browser works like charms – Sky21.86 Jan 03 '19 at 09:55

0 Answers0