将Ruby / Perl Soap请求转换为PHP

时间:2015-08-05 09:40:24

标签: php ruby perl soap

我有一个与Web肥皂服务器通信的Perl脚本,效果很好。但是我需要在PHP应用程序中获得相同的功能,并且在转换它时遇到很多麻烦。

工作的Perl看起来像这样:

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;

    }

并给出为会话生成客户ID的预期结果。

以下脚本在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"

然而,对php版本的尝试看起来像这样:

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);
}

并且出现以下错误:

  

SoapFault对象([message:protected] =&gt; SOAP-ERROR:解析WSDL:   无法从&#39; http://xx.x.xx.xx:8070/ShoreTelWebSDK/WebService&#39;加载   :无法加载外部实体   &#34; http://xx.x.xx.xx:8070/ShoreTelWebSDK/WebService&#34;   [string:Exception:private] =&gt; [code:protected] =&gt; 0 [文件:保护]   =&GT; /var/www/cgi-bin/test.php [line:protected] =&gt; 7 [追踪:例外:私人] =&gt;数组([0] =&gt;数组([file] =&gt;   /var/www/cgi-bin/test.php [line] =&gt; 7 [功能] =&gt; SoapClient [类]   =&GT; SoapClient [type] =&gt; - &GT; [args] =&gt;数组([0] =&gt; http://xx.x.xx.xx:8070/ShoreTelWebSDK/WebService)))   [上一个:例外:私人] =&gt; [faultstring] =&gt; SOAP-ERROR:解析   WSDL:无法加载   &#39; http://xx.x.xx.xx:8070/ShoreTelWebSDK/WebService&#39; :无法加载   外部实体&#34; http://xx.x.xx.xx:8070/ShoreTelWebSDK/WebService&#34;   [faultcode] =&gt; WSDL)

看起来加载WSDL时遇到问题,但Perl脚本没有任何问题,如何将其转换为PHP脚本?

我也试过像这样的php脚本:

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);

这导致服务器接受的所有可能请求的列表,但没有处理我的请求。

1 个答案:

答案 0 :(得分:1)

我最终能够在RobGudeon的帮助下完成这项工作。看起来我们需要使用Ruby版本与PHP所期望的匹配的URL。工作脚本是:

{{1}}