Reputation: 575
I have SoapUI working with this xml, but I need to consume that data on my server using php 5.3. I think I need to convert my $string into an array. the $xml = (array)simplexml_load_string($string); isn't throwing any errors, but the response from the call is NULL.
$string = '
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tran="http://www.cornerstoneondemand.com/Webservices/TranscriptAndTask">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-115E54B97689076253912">
<wsse:Username>me</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">word</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">dvhXLFiL4Aoi2KQ==</wsse:Nonce>
<wsu:Created>2016-10-19T15:26:02.539Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<tran:GetTranscriptAndTasks>
<tran:request>
<Request corpName="learning">
<User id="me">
<RequestTypes>
<Inbox/>
<Transcript inprogressOnly="false" pageNumber="1"/>
<Session pageNumber="1" upcomingOnly="true"/>
<Assigned assignedOnly="true"/>
<Approval approvalDateRequested="1967-08-13"/>
<Task pendingTasksOnly="true"/>
<SuggestedTraining pageNumber="1"/>
</RequestTypes>
</User>
</Request>
</tran:request>
</tran:GetTranscriptAndTasks>
</soapenv:Body>
</soapenv:Envelope>
';
$xml = (array)simplexml_load_string($string);
$soapClient = new SoapClient($wsdl, array('trace' => 1));
$response = $soapClient->GetTranscriptAndTasks($xml);
var_dump($response);
Any help is greatly appreciated!
Edit: I found https://github.com/sapankumarmohanty/lamp/blob/master/Crate-XML-2-Array that turns the xml into a nice array. But my result is still NULL... I copied the WSDL here http://www.markforsyth.com/TranscriptAndTaskService.wsdl if it helps.
Upvotes: 2
Views: 290
Reputation: 391
You can actually use xml code from SoapUI allmost direct.
Here are some code fragments from a code of mine:
Constructor for my class, that servs as a interface to a web service. wsdl is defined as a constant in the class:
public function __construct($username, $password) {
$this->client = new SoapClient(self::wsdl);
$this->client->__setSoapHeaders(self::securityHeader($username, $password));
}
Function in my class that return a security header used in the constructor:
private static function securityHeader($username, $password) {
$nsWSSE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
$nsWSU = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
$nonce = 'xxxxx';
$xml = '<nsWSSE:Security xmlns:nsWSSE="' . $nsWSSE . '" xmlns:nsWSU="' . $nsWSU . '">'
. '<nsWSSE:UsernameToken>'
. '<nsWSSE:Username>' . $username . '</nsWSSE:Username>'
. '<nsWSSE:Password>' . $password . '</nsWSSE:Password>'
. '<nsWSSE:Nonce>' . $nonce . '</nsWSSE:Nonce>'
. '<nsWSU:Created>' . gmdate('Y-m-d\TH:i:s\Z') . '</nsWSU:Created>'
. '</nsWSSE:UsernameToken>'
. '</nsWSSE:Security>';
$securityToken = new SoapVar($xml, XSD_ANYXML);
return new SoapHeader($nsWSSE, 'Security', $securityToken);
}
A function in my class, that makes a request to the WS-function "abc":
public function abc() {
$xml = ... paste your xml code from SoapUI here ...
$param = new SoapVar($xml, XSD_ANYXML);
return $this->client->abc($param);
}
Upvotes: 1