2

I have the following from a vendor API: enter image description here

and I neeed to create a Soap call using php. How do I go about doing that? so far I have this: but it does not work:

private function booking_soap_connect() {
        // the wsdl URL of your service to test 
        $serviceWsdl = 'https://apitest.com/bookingapi.asmx?WSDL';

        // the parmeters to initialize the client with 
        $serviceParams = array(
            'login' => 'un',
            'password' => 'pw'
        );

        // create the SOAP client 
        $client = new SoapClient($serviceWsdl, $serviceParams);

        $data['Brand'] = "All";
        $data['TourCode'] = "QBE";
        $data['DepartureCode'] = "8000321";
        $data['VendorId'] = "test";
        $data['VendorPassword'] = "test";

        $results = $client->GVI_DepartureInfo($data)
        echo $results;
    }

Please help

CodeGodie
  • 12,116
  • 6
  • 37
  • 66

3 Answers3

13

SOLVED: I finally got this going with the following code:

class WsseAuthHeader extends SoapHeader {

    private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';

    function __construct($user, $pass, $ns = null) {
        if ($ns) {
            $this->wss_ns = $ns;
        }

        $auth = new stdClass();
        $auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
        $auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);

        $username_token = new stdClass();
        $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);

        $security_sv = new SoapVar(
                new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns), SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
        parent::__construct($this->wss_ns, 'Security', $security_sv, true);
    }

}

$username = 'test';
$password = 'test123';
$wsdl = 'https://yoururl.com/api.asmx?WSDL';

$wsse_header = new WsseAuthHeader($username, $password);

$client = new SoapClient($wsdl, array(
    //"trace" => 1,
    //"exceptions" => 0
        )
);

$client->__setSoapHeaders(array($wsse_header));


$request = array(
    "functionResponseName" => array(
        'param1' => "string",
        "param2" => "string"
    )
);

$results = $client->FunctionName($request);

var_dump($results);
CodeGodie
  • 12,116
  • 6
  • 37
  • 66
  • Could you say if or not this differs to the answer http://stackoverflow.com/a/6677930/367456 and if it differs, outline in short, what the differences are? I know it's quite some time since you answered but you probably can take a look. – hakre Dec 22 '14 at 18:07
  • 1
    First try and all works fine... Thank you!! – Gabriel Anderson Jun 02 '16 at 18:40
  • 1
    Life savior ! From where did you get this code ? – Leeeeeeelo Nov 19 '16 at 23:31
  • Nice.. dont remember where I got it from. I think I came up with it myself, its been a while. Glad it helped you out. – CodeGodie Nov 21 '16 at 16:40
-1

Use Nusoap instead your Soap client might not work with your php version.

leo
  • 356
  • 4
  • 14
-1

Look at this my previous answer at Send XML with php via post. There should be everything you need to handle SOAP in php well.

Community
  • 1
  • 1
Fanda
  • 3,760
  • 5
  • 37
  • 56
  • I have looked at this answer and many others but no go. – CodeGodie Mar 12 '14 at 19:25
  • Witch part does not work for you? Be concrete. Why do you downvote? Better precise your question. – Fanda Mar 12 '14 at 19:30
  • I downvote because you are not giving me an answer. you are just pointing me to other links which I have already looked at.. I cannot get this going. I have the code which i tried above, and it just gives an error. I wrote the code above. All im asking is for someone to review and see where I made the error – CodeGodie Mar 12 '14 at 19:36
  • So, after all, see my answer again, how to make it work. – Fanda Mar 12 '14 at 19:38