Problem connecting to webservice using SoapClient

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mukunthan
Forum Newbie
Posts: 12
Joined: Sat Sep 13, 2008 12:52 am

Problem connecting to webservice using SoapClient

Post by mukunthan »

Hi all :D ,

My site has a member login which has to access the following webservice for authenticating the member to allow him to enter the member section of my site
https://www.apta.org/AM/APTAAPPS/Compon ... e.cfc?WSDL

This webservice has to return an XML output based on which i'll allow or disallow the member to enter into my website's member section. But instead of getting an XML output I getthe following error

Code: Select all

ERROR: HTTP-Could not connect to host
The code which I used is

Code: Select all

<?php
$client = new SoapClient('https://www.apta.org/AM/APTAAPPS/ComponentAuthWebService/aptamemberauthorize.cfc?WSDL');
$arguments = array(
   'mausername'=> 22586,
   'mapassword' => 'swisher',
   'componenttype' => 'Section',
   'components'=> 'L',
   'authusername' => 'heart',
   'authpassword' => 'lung',
   'authpagealias' => 'Login'
 
);

// Call RemoteFunction ()
$error = 0;

try {
   $result = $client->__soapCall('MemberAuth', $arguments);

} catch (SoapFault $fault) {
   $error = 1;
   echo 'Returned the following ERROR: ' .$fault->faultcode . '-' . $fault->faultstring ; 
}
print_r($result);
// kill object
unset($client);

?>
Since this is the first time I am accessing a webservice I am breaking my head over this . I will be very much obliged if someone could help me sort this thing.

Thanks in advance :)
User avatar
Sofw_Arch_Dev
Forum Commoner
Posts: 60
Joined: Tue Mar 16, 2010 4:06 pm
Location: San Francisco, California, US

Re: Problem connecting to webservice using SoapClient

Post by Sofw_Arch_Dev »

Mukunthan,

I had a similar problem when connecting to a web service. I could access the WSDL fine, but I could not access the service. I found that the problem was a proxy server sitting between my local machine and the web service. I had to add the following parameters to my SoapClient instantiation call:

Code: Select all

// Define proxyHost and proxyPort in a file global to your application or test.
// Then define an array of params for the SoapClient instantiation.
$params = array('trace' => true, 'proxy_host' => $proxyHost, 'proxy_port'  => $proxyPort );
$client = new SoapClient('https://www.apta.org/AM/APTAAPPS/ComponentAuthWebService/aptamemberauthorize.cfc?WSDL', $params );
This did the trick for me. Do you know if you're sitting behind a proxy server?
mukunthan
Forum Newbie
Posts: 12
Joined: Sat Sep 13, 2008 12:52 am

Re: Problem connecting to webservice using SoapClient

Post by mukunthan »

Hi,

Thanx for the reply, but I checked with the Client a few times and they specifically said that the above mentioned information are only required for connecting to the webservice.

So I tried printing the "Request" and "Response" in the catch section and the request get's printed except for the response. I believe that if it's behind a proxy then it won't be able to the return the request. Am I correct ?

Modified code follows

Code: Select all

<?php
$params = array('trace' => true );
$client = new SoapClient('https://www.apta.org/AM/APTAAPPS/ComponentAuthWebService/aptamemberauthorize.cfc?WSDL', $params );
 

$arguments = array(
   'mausername'=> 22586,
   'mapassword' => 'swisher',
   'componenttype' => 'Section',
   'components'=> 'L',
   'authusername' => 'heart',
   'authpassword' => 'lung',
   'authpagealias' => 'Login'
 
);

// Call RemoteFunction ()
$error = 0;

try {
   $result = $client->__soapCall('MemberAuth', $arguments);

} catch (SoapFault $fault) {
   $error = 1;
   echo 'Returned the following ERROR: ' .$fault->faultcode . '-' . $fault->faultstring ; 
   print "REQUEST:\n" . htmlentities($client->__getLastRequest()) . "\n<br /><br />";

	print "RESPONSE:\n" . htmlentities($client->__getLastResponse()) . "\n";
}
print_r($result);
// kill object
unset($client);
?>

The result follows

Code: Select all

Returned the following ERROR: HTTP-Could not connect to host

REQUEST:
      <?xml version="1.0" encoding="UTF-8"?>
      <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ComponentAuthWebService.APTAAPPS.AM" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
        <SOAP-ENV:Body>
          <ns1:MemberAuth>
            <mausername xsi:type="xsd:double">
22586
            </mausername>
            <mapassword xsi:type="xsd:string">
swisher
            </mapassword>
            <componenttype xsi:type="xsd:string">
Section
            </componenttype>
            <components xsi:type="xsd:string">
L
            </components>
            <authusername xsi:type="xsd:string">
heart
            </authusername>
            <authpassword xsi:type="xsd:string">
lung
            </authpassword>
            <authpagealias xsi:type="xsd:string">
Login
            </authpagealias>
          </ns1:MemberAuth>
        </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>
	  
	  
RESPONSE:
Thanx in advance
Post Reply