Od dwóch tygodni próbuję utworzyć usługę sieci Web w Perlu (z WSDL::Generator
) i wywołać ją za pomocą klienta napisanego w języku Perl.Nie można uzyskać usługi sieci Web Perl przy użyciu narzędzia WSDL :: Generator
Teraz staram podane przykłady z biblioteki specjalizuje się w WSDL: Soap::Lite
ale pojawia się błąd, który śledzi pojawiające
404 file not found at c.PL at line 7.
Pomożesz mi go rozwiązać?
Oto mój kod:
WorldFunctions.pm
(C: \ Perl \ SOAP-Lite \ WorldFunctions.pm): klasa
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), aby utworzyć plik WSDL WorldFunctions.pm klasy
#!/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 klient plik 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')."|";
Wiedząc, że korzystam z lokalnego serwera (z serwerem WAMP) i skopiowałem do mojego katalogu WorldFunctions.pm localhost/world.
Oto plik 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>
Czy jesteś pewien, że pliki, do których próbujesz uzyskać dostęp, rzeczywiście istnieją? Czy możesz je załadować w przeglądarce GUI? –
Przepraszam Brian, spóźniłem się, aby ci odpowiedzieć! ale pliki są umieszczone w odpowiednim miejscu i są one poprawne – Wael
Utknąłem na innym problemie: kiedy wykonam poniższy kod, wyświetli się komunikat "Nie można znaleźć lub załadować mod_perl w C:/Perl/site/lib/SOAP/transport/HTTP.pm linia 741 " ale zainstalowany moduł powodzeniem mod_apache2 Oto kod: ' code' #/usr/bin/perl używać mydła :: transport :: HTTP; SOAP :: Transport :: HTTP :: Apache -> dispatch_to ('WorldFunctions') -> uchwyt; pakiet WorldFunctions; sub new {bless {}, shift; } 'code' – Wael