Domanda

I tried using the example mentioned in below url. but got confused how they are building the $wrapper here. Can anyone tell me how to create to wrapper and what it should contain. http://www.sis.utoronto.ca/web_services/code_samples.html.

Can someone help me here since I am using wsse for the first time so dont know how to use it. I am making a soap call from PHP to .net wsse.

Please let me know how to pass headers in this example.

<?php
  class WSSESoapClient extends SoapClient {                                                                                           
protected $wsseUser;
protected $wssePassword;

public function setWSSECredentials($user, $password) {
    $this->wsseUser = $user;
    $this->wssePassword = $password;
}

public function __doRequest($request, $location, $action, $version, $one_way = 0) {
    if (!$this->wsseUser or !$this->wssePassword) {

        return parent::__doRequest($request, $location, $action, $version, $one_way = 0);
    }

    // get SOAP message into DOM
    $dom = new DOMDocument();
    $dom->loadXML($request);
    $xp = new DOMXPath($dom);
    $xp->registerNamespace('SOAP-ENV', 'http://schemas.xmlsoap.org/soap/envelope/');

    // search for SOAP header, create one if not found
    $header = $xp->query('/SOAP-ENV:Envelope/SOAP-ENV:Header')->item(0);
    if (!$header) {
        $header = $dom->createElementNS('http://schemas.xmlsoap.org/soap/envelope/', 'SOAP-ENV:Header');
        $envelope = $xp->query('/SOAP-ENV:Envelope')->item(0);
        $envelope->insertBefore($header, $xp->query('/SOAP-ENV:Envelope/SOAP-ENV:Body')->item(0));
    }

    // add WSSE header
    $usernameToken = $dom->createElementNS('http://schemas.xmlsoap.org/ws/2002/07/secext', 'wsse:UsernameToken');
    $username = $dom->createElementNS('http://schemas.xmlsoap.org/ws/2002/07/secext', 'wsse:Username', $this->wsseUser);
    $password = $dom->createElementNS('http://schemas.xmlsoap.org/ws/2002/07/secext', 'wsse:Password', $this->wssePassword);
    $usernameToken->appendChild($username);
    $usernameToken->appendChild($password);
    $header->appendChild($usernameToken);

    // perform SOAP call
    $request = $dom->saveXML();

    return parent::__doRequest($request, $location, $action, $version, $one_way = 0);
}

  } // class WSSESoapClient

  $wsdl = 'Mywsdlurl';
  $sClient = new WSSESoapClient ($wsdl,array( "trace" => 1 ));


    $sClient->setWSSECredentials('username', 'password');

    $wrapper->AccountName = new SoapVar("NEw User", XSD_STRING);
    $wrapper->AccountInfo->propertyID = new SoapVar(2, XSD_STRING);


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

echo $sClient->__getLastRequest();
 // "<br>" .
//  $sClient->__getLastResponse();

?>

When I check the __getLastRequest it is not attaching the headers defined in _doRequest;

Please let me know what wrong I am doing here.

È stato utile?

Soluzione

I have implemented the UserNameToken using PasswordDigest in my Moodle module that integrates with Skillsofts OLSA Web Services.

Take a look at: http://code.google.com/p/moodle2-skillsoft-activity/source/browse/trunk/skillsoft/olsalib.php#40

This is where I create a wrapper around the PHP SoapClient to support sending the UserNameToken with password digest, you can tweak this to do plain password etc etc

It has some Moodle specific code for getting things like proxy to use etc, and where to "cache" the WSDL on the filesystem (makes it faster setting up the client - rather than each time you set it up pulling down the WSDL etc)

Then look at: http://code.google.com/p/moodle2-skillsoft-activity/source/browse/trunk/skillsoft/olsalib.php#483

Where I call one of the web services and you can see how the client is setup and how the username/password are passed across.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top