1
votes

I have a Perl script that communicates with a web soap server and does great. However I need to get this same functionality in a PHP application and am having a lot of trouble converting this over.

The working Perl looks like this:

use warnings;
use SOAP::Lite;
use CGI;
use Data::Dumper;
sub  trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
print "Content-type:text/html\n\n";

# Use SoapLite to create a connection to our Web service.  URI is the namespace for our service,
# proxy is the endpoint of our service.  The "on_action" is necessary to reformat SoapLite's
# SOAP request to match what a .NET service needs.

my $myWebService = SOAP::Lite
  -> uri('http://www.ShoreTel.com/ProServices/SDK/Web')
  -> proxy('http://xx.x.xx.xx:8070/ShoreTelWebSDK/WebService')
  -> on_action(sub {sprintf '%s/ShoreTelWebService/%s', $_[0], $_[1]});

my $query = new CGI;
my $ip = $query->remote_host;                    # IP address of remote party...use later as unique identifier


    # To use our service, we need to register ourselves as a client...use remote IP address
    # as a unique name for association to this session.

    my $regClientResult = $myWebService->RegisterClient(SOAP::Data->name('clientName' => $ip));
    if ($regClientResult->fault)
    {
      print '<p>FAULT', $myClientID->faultcode, ', ', $myClientID->faultstring;
    }
    else
    {
      # Retrieve client ID which we will be using for subsequent communication.

      $myClientID = $regClientResult->valueof('//RegisterClientResponse/RegisterClientResult/');
      print $myClientID;

    }

And gives the expected result of producing a Client ID for the session.

The following script also does the same thing in ruby:

require "soap/wsdlDriver"
require 'optparse'
require 'ostruct'
require 'pp'


def has_events(events)
  return (events["GetEventsResult"] != nil) && (events["GetEventsResult"]["ShoreTelEventBase"] != nil)
end



begin
  options.parse!(ARGV)
rescue OptionParser::ParseError => e
  puts e
end

# create wsdl driver for SDK
wsdl = "http://10.1.10.20:8070/ShoreTelWebSDK?wsdl"
driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
driver.wiredump_file_base = "/var/www/WebSDK.out"

# register with the SDK
id = driver.RegisterClient("clientName" =>"ruby")
handle = id.registerClientResult
print "\nClient ID ", handle, " has been registered.\n\n"

However attempt at a php version looks like this:

try
{
$soap_url = 'http://10.1.10.20:8070/ShoreTelWebSDK/WebService';
$client = new SoapClient($soap_url);

$header = new SoapHeader(

        'http://www.ShoreTel.com/ProServices/SDK/Web',
        'RegisterClient',
        array(
            'clientName' => 'xx.xx.xx.xxx'
        )
    );
    $client->__setSoapHeaders($header);
    var_dump($client->__getFunctions());    
}
catch (Exception $e)
{
   print_r($e);
}

And is giving the following errors:

SoapFault Object ( [message:protected] => SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://xx.x.xx.xx:8070/ShoreTelWebSDK/WebService' : failed to load external entity "http://xx.x.xx.xx:8070/ShoreTelWebSDK/WebService" [string:Exception:private] => [code:protected] => 0 [file:protected] => /var/www/cgi-bin/test.php [line:protected] => 7 [trace:Exception:private] => Array ( [0] => Array ( [file] => /var/www/cgi-bin/test.php [line] => 7 [function] => SoapClient [class] => SoapClient [type] => -> [args] => Array ( [0] => http://xx.x.xx.xx:8070/ShoreTelWebSDK/WebService ) ) ) [previous:Exception:private] => [faultstring] => SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://xx.x.xx.xx:8070/ShoreTelWebSDK/WebService' : failed to load external entity "http://xx.x.xx.xx:8070/ShoreTelWebSDK/WebService" [faultcode] => WSDL )

It looks like it is have issues loading the WSDL, but the Perl script doesn't have any issues, how can I translate this to the PHP script?

I also tried the php script like this:

try
{
$soap_url = 'http://10.1.10.20:8070/ShoreTelWebSDK?wsdl';
$client = new SOAPClient($soap_url, array( 'proxy_host' => '10.1.10.20', 'proxy_port' => 8070, 'trace' => 1 ) );
$client = new SoapClient($soap_url);

$header = new SoapHeader(

        'http://www.ShoreTel.com/ProServices/SDK/Web',
        'RegisterClient',
        array(
            'clientName' => 'xx.x.xx.xxx'
        )
    );
    $client->__setSoapHeaders($header);
    var_dump($client->__getFunctions());    
}
catch (Exception $e)
{
   print_r($e);

This resulted in a list of all possible requests the server accepts, but did not process my request.

1
is the perl running on the same server & as the same user? do you need to set a proxy server? what happens if you try wget 10.1.10.20:8070/ShoreTelWebSDK/WebService as the same user you're running the php script as?Rob G
@RobGudgeon Yes they are the same server. It shouldn't nee a proxy since it works with the Perl script. A wget results in a error. I am not sure how the Perl script is pulling it that works.Joel Lewis
The perl is using a proxy server :) What's the wget error? Try this, replacing the x.x.x.x with whatever proxy server the perl is using: $client = new SOAPClient($soap_url, array( 'proxy_host' => x.x.x.x, 'proxy_port' => 8070, 'trace' => 1 ) );Rob G
@RobGudgeon it was a 400 error.Joel Lewis
post the full error/outputRob G

1 Answers

1
votes

I was finaly able to make this work with some help from RobGudeon. It looks like we needed to use the URL the Ruby version wich matched what PHP was expecting. The working script is:

try
{
$soap_url = 'http://xx.x.xx.xx:8070/ShoreTelWebSDK?wsdl';
$client = new SOAPClient($soap_url, array( 'proxy_host' => 'xx.x.xx.xx', 'proxy_port' => 8070, 'trace' => 1 ) );
$client = new SoapClient($soap_url);

$header = new SoapHeader(

        'http://www.ShoreTel.com/ProServices/SDK/Web',
        'RegisterClient'

    );
    $client->__setSoapHeaders($header);
    var_dump($client->RegisterClient(array(
            'clientName' => 'xx.xx.xx'
        )));    
}
catch (Exception $e)
{
   print_r($e);
}