Reputation: 574
I am trying to call SOAP webservice for which WSDL file is already given. I am able to test these SOAP Request and Response through SOAP UI or Chrome Boomerang. I am able to get response properly.
Client has shared WSDL URL, Username, and Password. How can I use PHP code to call services. My concern is that I have request and response in XML format.
Can I send XML directly in the request. How could I make a SOAP Request with these given XML-Request information. Do I need to parse into objects or arrays. Thanks in advance.
XML Request that sends me response on SOAP UI is -
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Header>
<xsd:sample_Common_Header>
<xsd:Include_Reference_Descriptors_In_Response>false</xsd:Include_Reference_Descriptors_In_Response>
</xsd:sample_Common_Header>
<wsse:Security 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>
<wsse:Username>Assessment@tenant</wsse:Username>
<wsse:Password>Test@1234</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</env:Header>
<env:Body>
<wd:Get_Assess_Candidate_Request
xmlns:wd="urn:com.sample/bsvc"
wd:version="v29.0">
<wd:Request_Criteria>
<wd:Candidate_Criteria_Data>
<wd:Candidate_Reference>
<wd:ID wd:type="Candidate_ID">C0000417</wd:ID>
</wd:Candidate_Reference>
</wd:Candidate_Criteria_Data>
</wd:Request_Criteria>
<wd:Response_Filter>
<wd:As_Of_Effective_Date>2018-01-16</wd:As_Of_Effective_Date>
<wd:As_Of_Entry_DateTime>2018-01-16T11:17:34</wd:As_Of_Entry_DateTime>
<wd:Page>1</wd:Page>
<wd:Count>100</wd:Count>
</wd:Response_Filter>
</wd:Get_Assess_Candidate_Request>
</env:Body>
</env:Envelope>
Upvotes: 0
Views: 2000
Reputation: 574
function AddWSSUsernameToken($client, $username, $password)
{
$wssNamespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
$username = new SoapVar($username,
XSD_STRING,
null, null,
'Username',
$wssNamespace);
$password = new SoapVar($password,
XSD_STRING,
null, null,
'Password',
$wssNamespace);
$usernameToken = new SoapVar(array($username, $password),
SOAP_ENC_OBJECT,
null, null, 'UsernameToken',
$wssNamespace);
$usernameToken = new SoapVar(array($usernameToken),
SOAP_ENC_OBJECT,
null, null, null,
$wssNamespace);
$wssUsernameTokenHeader = new SoapHeader($wssNamespace, 'Security', $usernameToken);
$client->__setSoapHeaders($wssUsernameTokenHeader);
}
function get_soap_client(){
$username = 'Assessment@tenant';
$password = 'Test@1234';
$wsdl = 'https://wd5-impl-
services1.workday.com/ccx/service/tenant/Recruiting/v29.1?wsdl';
$options = array(
'uri'=>'http://schemas.xmlsoap.org/soap/envelope/',
'style'=>SOAP_RPC,
'use'=>SOAP_ENCODED,
'soap_version'=>SOAP_1_1,
'cache_wsdl'=>WSDL_CACHE_NONE,
'connection_timeout'=>15,
'trace'=>true,
'encoding'=>'UTF-8',
'exceptions'=>true,
);
$client = new SoapClient($wsdl, $options);
AddWSSUsernameToken($client, $username, $password);
return $client;
}
try
{
$params = array(); //define your parameters here
$client = get_soap_client();
$response = $client->__soapCall('method-name',$params);
}
catch(Exception $e){
echo $e->getCode(). '<br />'. $e->getMessage();
}
Upvotes: 4
Reputation: 760
You can send the XML string with curl but I wouldn't advise to do.
My advice is to use a WSDL to PHP generator such as the PackageGenerator project. Using the generated SDK will avoid you from wondering how to construct the request. Moreover, the response will be handled nicely and you'll end up with full OOP approach.
Upvotes: 0