perl - 来自 tarball 的 perl + SOAP + WSDL 的完整工作 HelloWorld 示例

标签 perl soap

我想知道是否有人可以提供 SOAP 1.2 的完整工作示例服务器(无 CGI)+ SOAP 1.2带有 WSDL 的客户文件。

自 1 周以来我尝试的任何事情都失败了。

我最后一次尝试 SOAP::Transport::HTTP::Daemon模块给我:

SOAP::Serializer::envelope: Client Denied access to method (AnalyzeDocument) in class (main) at /usr/share/perl5/site_perl/SOAP/Lite.pm line 2806

我打开了很多 Firefox 标签页,但在 2012 年没有一个解决方案有效。
/usr/share/perl5/site_perl/SOAP/Lite.pm相关部分是
# TODO - sort this mess out:
# The task is to test whether the class in question has already been loaded.
#
# SOAP::Lite 0.60:
#  unless (defined %{"${class}::"}) {
# Patch to SOAP::Lite 0.60:
# The following patch does not work for packages defined within a BEGIN block
#  unless (exists($INC{join '/', split /::/, $class.'.pm'})) {
# Combination of 0.60 and patch did not work reliably, either.
#
# Now we do the following: Check whether the class is main (always loaded)
# or the class implements the method in question
# or the package exists as file in %INC.
#
# This is still sort of a hack - but I don't know anything better
# If you have some idea, please help me out...
#
    unless (($class eq 'main') || $class->can($method_name)
        || exists($INC{join '/', split /::/, $class . '.pm'})) {

        # allow all for static and only specified path for dynamic bindings
        local @INC = (($static ? @INC : ()), grep {!ref && m![/\\.]!} $self->dispatch_to());
        eval 'local $^W; ' . "require $class";
        die "Failed to access class ($class): $@" if $@;
        $self->dispatched($class) unless $static;
    }

    die "Denied access to method ($method_name) in class ($class)"
        unless $static || grep {/^$class$/} $self->dispatched;

    return ($class, $method_uri, $method_name);
}

最佳答案

解决方案

此解决方案使用 Apache服务器 + mod_perlDebian (或衍生)

vi /etc/apache2/sites-available/default

添加 block :
<Location /SOAP/>
    SetHandler perl-script
    PerlHandler Apache::SOAP
    PerlSetVar dispatch_to '/usr/share/perl5/'
</Location
/usr/share/perl5/HelloWorld.pm模块文件:
package HelloWorld;

use strict;
use warnings;

sub sayHello {
    return "Hello @_\n";
}

1;

SOAP 客户端:
use SOAP::Lite +trace;

use strict; use warnings;

my $client = SOAP::Lite->new;
my $ua = $client->schema->useragent;
$ua->agent("Fubar! 0.1");

my $response = $client
    # WSDL url
    ->service("http://example.com/HelloWorld.xml") // the below exposed wsdl

    # method from SOAP server Module
    ->sayHello("foo", "bar");

print $response;
WSDL文件 :
 <definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
   xmlns:s="http://www.w3.org/2001/XMLSchema"
   xmlns:s0="urn:HelloWorld"
   targetNamespace="urn:HelloWorld"
   xmlns="http://schemas.xmlsoap.org/wsdl/">
   <types>
     <s:schema targetNamespace="urn:HelloWorld">
     </s:schema>
   </types>
   <message name="sayHello">
     <part name="name" type="s:string" />
     <part name="givenName" type="s:string" />
   </message>
   <message name="sayHelloResponse">
     <part name="sayHelloResult" type="s:string" />
   </message>

   <portType name="Service1Soap">
     <operation name="sayHello">
       <input message="s0:sayHello" />
       <output message="s0:sayHelloResponse" />
     </operation>
   </portType>

   <binding name="Service1Soap" type="s0:Service1Soap">
     <soap:binding transport="http://schemas.xmlsoap.org/soap/http"
         style="rpc" />
     <operation name="sayHello">
       <soap:operation soapAction="urn:HelloWorld#sayHello"/>
       <input>
         <soap:body use="encoded"
           encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
       </input>
       <output>
         <soap:body use="encoded"
           encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
       </output>
     </operation>
   </binding>
   <service name="HelloWorld">
     <port name="HelloWorldSoap" binding="s0:Service1Soap">
         <soap:address location="http://localhost:80/SOAP/" />
     </port>
   </service>
 </definitions>

关于perl - 来自 tarball 的 perl + SOAP + WSDL 的完整工作 HelloWorld 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13895120/

相关文章:

javascript - 从 Node.js 调用 SOAP 服务

perl - 当 "Can' t 通过包 y 定位对象方法 x 时打印堆栈跟踪"(Perl)

Perl:多维哈希

xml - 使用 XML::LibXML::XPathContext 通过 Perl 解析 XML

jquery - 出现网络错误 415 - 不支持的媒体类型

performance - 为什么 HTTP/SOAP 被认为是 "thick"

php - 有没有人成功使用 PHP 从亚马逊卖家中心下载订单?

php - 如何在 REDHAT 5 上安装 PHP SOAP

regex - 如何按字母顺序搜索包含字母的六个字母的单词

perl - 需要 Perl 就地编辑不在命令行上的文件