PHP has an easy way to communicate with a SOAP server:
https://secure.php.net/manual/en/book.soap.php
The SOAP extension must be installed for this to work; you can check the PHP info page or type php -m at the command line to verify.
Hi DionDesigns,
Yes I’m using
$client = new SoapClient($wsdl,
array(
'trace' => 1,
'cache_wsdl' => WSDL_CACHE_NONE,
'soap_version' => SOAP_1_2
));
…
$authvalues = new SoapVar($User_Credentials, SOAP_ENC_OBJECT);
…
$header = new SoapHeader($tns, 'User_Credentials', $authvalues, false);
…
$client->__setSoapHeaders(array($header));
…
$soapResponse = $client->Is_Alive();
$lastRespHeaders = $client->__getLastResponseHeaders();
$lastResquest = $client->__getLastRequest();
$lastResponse = $client->__getLastResponse();
but microsoft is not accepting ns1
If I use the online https://wsdlbrowser.com/
and enter the WSDL is also creates XML with the ns1 bound to the xmlns
So I would think the ASP server should accept it but it doesn’t.
-
This reply was modified 8 years, 1 month ago by
Ken Stone.
Got it working:
I removed the soapvar from the header and just use the PHP class straight away.
The difference is that now
<env:Header>
<ns1:User_Credentials>
<ns1:str_Username>jklsafdljk</ns1:str_Username>
<ns1:str_Password>jkasdjl</ns1:str_Password>
</ns1:User_Credentials>
</env:Header>
ns1 is also on the username and password
where previously it was not:
<SOAP-ENV:Header>
<ns1:User_Credentials>
<str_Username>asdasdasd</str_Username>
<str_Password>asdasdads</str_Password>
</ns1:User_Credentials>
</SOAP-ENV:Header>
I got a clue from a google search result. I didn’t even click through but I saw ‘you don’t have to use a soapvar in the header you can use a regular php class’. At this point I was willing to try anything…
So I immediately did
//$header = new SoapHeader($tns, 'User_Credentials', $authvalues, false);
$header = new SoapHeader($tns, 'User_Credentials', $User_Credentials, false);
-
This reply was modified 8 years, 1 month ago by
Ken Stone.
I haven’t needed to access a SOAP server in a couple years, but I remember having all sorts of problems until I added the following line to php.ini and restarting php-fpm:
soap.wsdl_cache_enabled=0
Maybe that will be of some help to you.
At this point though I’m wondering since the online SOAP client at wsdlbrowser.com created the same XML as the PHP code based on the WSDL file if there is some issue with the WSDL file?
Hi Dion,
I have:
'cache_wsdl' => WSDL_CACHE_NONE,
in the instantiation of the soap client.
Working now. but THANKS
I have a similar issue now when calling a method that has parameters in the body.
PHP SOAP is using xsi:type=”ns1… instead of adding ns1 to each value in the parameter object. Does anyone know if there is a way to modify this behavior?
<SOAP-ENV:Body>
<ns1:Process_Credit_Application xsi:type="ns1:obj_Credit_Application">
<ApplicantIP>192.168.1.1</ApplicantIP>
I think what is needed is:
<SOAP-ENV:Body>
<ns1:Process_Credit_Application>
<ns1:obj_Credit_Application>
<ns1:ApplicantIP>192.168.1.1</ns1:ApplicantIP>
-
This reply was modified 8 years, 1 month ago by
Ken Stone.
I still have no idea how to do it within the PHP SOAP library so I went ahead and just rolled my own XML for now.
public function get_xml($method, $type, $data_assoc_array){
$my_xml = '<ns1:' . $method . '><ns1:'. $type . '>';
foreach($data_assoc_array as $key => $val){
$my_xml .= '<ns1:' . $key . '>' . $val . '</ns1:' . $key . '>';
}
$my_xml .= '</ns1:' . $type . '></ns1:' . $method . '>';
return $my_xml;
}