0

Can someone provide me a PHP example of how to make a WSSoapClient call to a wsdl webservice at https://gateway2.pagosonline.net/ws/WebServicesClientesUT?wsdl .

I have looked everywhere for code examples and could not find how to call this. i see that you can extend the SoapClient class but i am lost on how to structure the call itself. thank you so much.

Example"

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"     xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ser="http://server.webservices.web.v2.pagosonline.net"> 
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" 
 xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-    secext1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>1</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-    token-profile-1.0#PasswordText">
123456</wsse:Password>
</wsse:UsernameToken>
</wsse:Security> 
</soapenv:Header>
<soapenv:Body>
<ser:getVersion soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</soapenv:Body></soapenv:Envelope>
jacksprater
  • 27
  • 1
  • 4

1 Answers1

2

Firstly, you need to initialize a new SoapClient object, passing in the URL to your WSDL file like so:

$client = new SoapClient("https://gateway2.pagosonline.net/ws/WebServicesClientesUT?wsdl");

Then you can call service methods like any other object method like so:

$verificaCuenta = true;
$result = $client->setVerificaCuenta($verificaCuenta);

To get a list of all available methods, once you have created your $client object, you can call __getFunctions() like this:

$client = new SoapClient("https://gateway2.pagosonline.net/ws/WebServicesClientesUT?wsdl");
$functions = $client->__getFunctions();
var_dump($functions);

Note: you must have php_soap and php_openssl enabled in your php.ini file for this to work.

Edit: Seems like the service you are calling requires wsse headers. I'm no expert, but it looks like PHP does not have great support for that kind of thing.

Found a project on Google Code that appears to make wsse easy with PHP. Link here: https://code.google.com/p/wse-php/source/browse/

You can just grab the soap-wsse.php and the xmlseclibs.php files.

Then include the soap-wsse.php file into your code and extend the soap client like this:

require "soap-wsse.php";
class mySoap extends SoapClient {

    function __doRequest($request, $location, $saction, $version) {
        $doc = new DOMDocument('1.0');
        $doc->loadXML($request);

        $objWSSE = new WSSESoap($doc);

        $objWSSE->addUserToken("YOUR_USERNAME_HERE", "YOUR_PASSWORD_HERE", TRUE);

        return parent::__doRequest($objWSSE->saveXML(), $location, $saction, $version);
    }
}

Then you should be able to talk to the webservice like this:

$wsdl = 'https://gateway2.pagosonline.net/ws/WebServicesClientesUT?wsdl';    
$sClient = new mySoap($wsdl, array('trace'=>1));

try {
    $verificaCuenta = true;
    $result = $sClient->setVerificaCuenta($verificaCuenta);
    print_r($result->return);
} catch (SoapFault $fault) {
    print("Fault string: " . $fault->faultstring . "\n");
    print("Fault code: " . $fault->detail->WebServiceException->code . "\n");
}

echo $sClient->__getLastRequest() . "\n" . $sClient->__getLastResponse();

Disclaimer

I have not tested any of the above code, hopefully it can put you on the right path.

Good luck

Will Warren
  • 1,294
  • 15
  • 33
  • Just wanted to make sure the above would handle the necessary header security for this particular webservice. thand this will pass the necessary security headers? i have attached an image to this question with an example i was given of how the call should look with proper security headers. can you comment please? thanks again – jacksprater Mar 03 '13 at 17:26
  • I updated my answer - hopefully it can point you in the right direction. That's as far as my knowledge goes unfortunately. – Will Warren Mar 04 '13 at 01:15
  • If you need WS-Security headers, see this question: http://stackoverflow.com/questions/953639/connecting-to-ws-security-protected-web-service-with-php – scotru Aug 08 '14 at 06:01