Reputation: 325
I am using PHP and have never used SOAP and PHP before.
I need to build a Soap PHP Client which is calling and retrieves information from a Soap server .NET Web service.
I'm currently working on getting information for Doctors in Dutch Health care system .for Every doctor which is registered in the Dutch of health care system you can retrieve his information through his unique unique BIG ID - 11 digit unique number ) from a SOAP web-service using WSDL.
So when I am calling the SOAP server : (link of the server is below)
into this a Testing web site (like soapclinet.com)
my XML response is correct and looks exactly like this XML below in brackets the information of the doctor that i want to capture in php.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ListHcpApprox3Result xmlns="http://services.cibg.nl/ExternalUser">
<ListHcpApprox>
<ListHcpApprox3>
<HcpNumber>200822</HcpNumber>
<BirthSurname> [Surname of the Doctor]</BirthSurname>
<MailingName> [Mailing name of the doctor] </MailingName>
<Initial> [Initials of the doctor] </Initial>
<Gender> [Gender of the doctor] </Gender>
<ArticleRegistration>
<ArticleRegistrationExtApp>
<ArticleRegistrationNumber> [unique BIG ID] </ArticleRegistrationNumber>
<StartDate>1998-12-10T00:00:00</StartDate>
<EndDate xsi:nil="true"/>
<TypeOfSpecialismId>15</TypeOfSpecialismId>
</SpecialismExtApp>
</Specialism>
<Mention/>
<JudgmentProvision/>
<Limitation/>
</ListHcpApprox3>
</ListHcpApprox>
</ListHcpApprox3Result>
</soap:Body>
</soap:Envelope>
I need to build a PHP web page which will do exactly the same SOAP call.
the address of the wsdl file is this:
webservices.cibg.nl/Ribiz/OpenbaarV2.asmx?wsdl.asmx?wsdl
The soap server address is this: http://webservices-acc.cibg.nl/Ribiz/OpenbaarV2.asmx
The soap action is this: http://services.cibg.nl/ExternalUser/ListHcpApprox3
and the SOAP message that i sent is this:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<listHcpApproxRequest xmlns="http://services.cibg.nl/ExternalUser">
<WebSite>Ribiz</WebSite>
<RegistrationNumber> [BIG ID number of the doctor] </RegistrationNumber>
</listHcpApproxRequest>
</soap:Body>
</soap:Envelope>
(in brackets is the BIG ID number of the doctor that we send in SOAP server)
How can I write the above SOAP action into PHP code and store in PHP the variables of the XML that i get as response ?
the variables in XML response that I need to store in php code are these...
<HcpNumber>200822</HcpNumber>
<BirthSurname> [Surname of the Doctor]</BirthSurname>
<MailingName> [Mailing name of the doctor] </MailingName>
<Initial> [Initials of the doctor] </Initial>
<Gender> [Gender of the doctor] </Gender>
Update1: This is the output of the var_dump. Where xxxxxxx are the values that I want to store in php variables!
object(stdClass)[2]
public 'ListHcpApprox' =>
object(stdClass)[3]
public 'ListHcpApprox3' =>
object(stdClass)[4]
public 'HcpNumber' => string 'xxxxxxxxx' (length=6)
public 'BirthSurname' => string 'xxxxxxxxxxx' (length=9)
public 'MailingName' => string 'xxxxxxxxxxxxxxxxxx' (length=18)
public 'Initial' => string 'xxxxxxxxxxxx' (length=8)
public 'Gender' => string 'x' (length=1)
public 'ArticleRegistration' =>
object(stdClass)[5]
...
public 'Specialism' =>
object(stdClass)[7]
...
public 'Mention' =>
object(stdClass)[9]
...
public 'JudgmentProvision' =>
object(stdClass)[10]
...
public 'Limitation' =>
object(stdClass)[11]
...
Upvotes: 4
Views: 9188
Reputation: 64526
PHP has a native SoapClient class that makes it easy to call SOAP services. It provides a simple interface allowing you to use native PHP arrays and objects for the request and response data, and handles the intricacies of the SOAP envelope and WSDL.
// create a new SoapClient and pass it the WSDL
$client = new SoapClient('http://webservices.cibg.nl/Ribiz/OpenbaarV2.asmx?WSDL');
// define the input parameters for the webservice call
$params = array('WebSite' => 'Ribiz', 'RegistrationNumber' => 'xxxxxxxxxx');
// invoke the ListHcpApprox3 method
$response = $client->ListHcpApprox3($params);
// print out the response to see its structure
var_dump($response);
You can pick the variables out of the response like this:
$data = $response->ListHcpApprox->ListHcpApprox3
$HcpNumber = $data->HcpNumber;
$BirthSurname = $data->BirthSurname;
echo $HcpNumber;
Upvotes: 5