gpt4 book ai didi

perl - 无法使用 WSDL::Generator 运行 Perl Web 服务

转载 作者:行者123 更新时间:2023-12-03 15:03:02 25 4
gpt4 key购买 nike

两周以来,我一直在尝试用 Perl(使用 WSDL::Generator )创建一个 Web 服务,并用一个用 Perl 编写的客户端调用它。

现在我尝试使用专门研究 WSDL 的库提供的示例: Soap::Lite
但我收到一个不断出现的错误

404 file not found at c.PL at line 7.

你能帮我解决吗?

这是我的代码:
WorldFunctions.pm (C:\Perl\SOAP-Lite\WorldFunctions.pm) :类
package WorldFunctions;
sub new { bless {}, shift; }
sub Hello { my ($s, $name) = @_;
return 'Hello, ' . $name . "\n";
}
sub GoodBye { my ($s, $name) = @_;
return 'Goodbye, ' . $name . "\n";
}
a.pl (C:\Perl\SOAP-Lite\a.pl):创建类 WorldFunctions.pm 的 WSDL 文件
#!/usr/bin/perl
use WSDL::Generator;
my $init = {
'schema_namesp' => 'http://localhost/world/WorldFunctions.xsd',
'services' => 'WorldFunctions',
'service_name' => 'WorldFunctions',
'target_namesp' => 'http://localhost/world',
'documentation' => 'Simple Hello World SOAP Service.',
'location' => 'http://localhost/world'
};
my $w = WSDL::Generator->new($init);
WorldFunctions->Hello('Joe');
WorldFunctions->GoodBye('Joe');
print $w->get(WorldFunctions); # Returns the WSDL code for a specific class
open(TOTO,"<a.wsdl");
close(TOTO);
open(TOTO,">a.wsdl");
print TOTO $w->get(WorldFunctions);
close(TOTO);
c.pl (C:\Perl\SOAP-Lite\c.pl):perl 客户端 WSDL 文件
#!/usr/bin/perl 
use DBI();
use CGI;
use SOAP::Lite;
my $service = SOAP::Lite-> service('file:a.wsdl');
print "test retour : |".$service-> Hello('Joe')."|";

知道我使用本地服务器(带有 WAMP 服务器)并且我复制到我的目录 WorldFunctions.pm localhost/world 中。

这是 WSDL 文件:
<?xml version="1.0"?>
<definitions name="WorldFunctions" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://localhost/world" xmlns:tns="http://localhost/world" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsdl="http://localhost/world/WorldFunctions.xsd">
<types>
<xsd:schema targetNamespace="http://localhost/world/WorldFunctions.xsd">
<xsd:element name="GoodByeRequest" type="xsd:string" />
<xsd:element name="GoodByeResponse" type="xsd:string" />
<xsd:element name="HelloRequest" type="xsd:string" />
<xsd:element name="HelloResponse" type="xsd:string" />
</xsd:schema>
</types>
<message name="GoodByeRequest">
<part name="GoodByeRequestSoapMsg" element="xsdl:GoodByeRequest"/>
</message>
<message name="GoodByeResponse">
<part name="GoodByeResponseSoapMsg" element="xsdl:GoodByeResponse"/>
</message>
<message name="HelloRequest">
<part name="HelloRequestSoapMsg" element="xsdl:HelloRequest"/>
</message>
<message name="HelloResponse">
<part name="HelloResponseSoapMsg" element="xsdl:HelloResponse"/>
</message>
<portType name="WorldFunctionsWorldFunctionsPortType">
<operation name="GoodBye">
<input message="tns:GoodByeRequest" />
<output message="tns:GoodByeResponse" />
</operation>
<operation name="Hello">
<input message="tns:HelloRequest" />
<output message="tns:HelloResponse" />
</operation>
</portType>
<binding name="WorldFunctionsWorldFunctionsBinding" type="tns:WorldFunctionsWorldFunctionsPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GoodBye">
<soap:operation style="document" soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="Hello">
<soap:operation style="document" soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="WorldFunctions">
<documentation>
Simple Hello World SOAP Service.
</documentation>
<port name="WorldFunctionsWorldFunctionsPort" binding="tns:WorldFunctionsWorldFunctionsBinding">
<soap:address location="http://localhost/world"/>
</port>
</service>
</definitions>

最佳答案

看起来你没有映射 http://localhost/world到可以处理请求的 SOAP 处理程序,因此您将获得该 URL 的 404。

您需要配置 apache,以便该 URL 上有内容。

http://metacpan.org/pod/SOAP::WSDL::Server::Mod_Perl2

关于perl - 无法使用 WSDL::Generator 运行 Perl Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10138127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com