2

SOAP :: Liteを使用してSOAPサービスを作成しようとしていますが、値が返されません。初期化されていない値$resultの使用エラーがsoap_client.plの6行目に出力されます。

<VirtualHost 192.168.1.187:80>
 ServerName perl.qlc.net
 ServerAlias www.perl.qlc.net
 DocumentRoot /web/perl.qlc.net/htdocs
 ErrorLog /var/log/httpd/perl.qlc.net_error_log
 TransferLog /var/log/httpd/perl.qlc.net_access_log
      <Directory "/web/perl.qlc.net/htdocs">
        <FilesMatch "\.mhtml$|\.pl$|\.html$">
                Options         +ExecCGI
                AddHandler      cgi-script .cgi .pl .html
                SetHandler      perl-script
                PerlHandler     ModPerl::Registry
                PerlSendHeader  On
        </FilesMatch>
      </Directory>
 DirectoryIndex index.phtml index.htm index.html index.php3 index.php
</VirtualHost>

インストールされているperlモジュール:

MIME::Parser
SOAP::Lite

Apacheモジュール:

mod_perl

ソープサーバー:math.pl

#!/usr/bin/perl -w
use strict;
#use warnings;
use SOAP::Lite;
use SOAP::Transport::HTTP;

print "Content-type:text/xml\r\n\r\n";
#I have added above line because apache was throwing 500 error.

my $soap = SOAP::Transport::HTTP::CGI->new(
    dispatch_to => 'Arithmetic'
);
$soap->handle(); 

package Arithmetic;
sub add {
        return $_[1] + $_[2];
}
1;

ソープクライアント:soap_client.pl

#!/usr/bin/perl -w
#use SOAP::Lite +trace =>'debug';
use SOAP::Lite;
my $result = 0;
my $client = SOAP::Lite->service("http://perl.qlc.net/math.wsdl");
print $result = $client->add(10, 20);

Wsdlファイル:math.wsdl

<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://perl.qlc.net/math.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="HelloService" targetNamespace="http://perl.qlc.net/math.wsdl">
<message name="addRequest">
    <part name="operand1" type="xsd:float" />
    <part name="operand2" type="xsd:float" />
</message>
<message name="addResponse">
    <part name="response" type="xsd:float" />
</message>
<portType name="Hello_PortType">
    <operation name="add">
        <input message="tns:addRequest"/>
        <output message="tns:addResponse"/>
    </operation>
</portType>
<binding name="Hello_Binding" type="tns:Hello_PortType">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="add">
        <soap:operation soapAction="add"/>
        <input>
            <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:examples:helloservice" use="encoded"/>
        </input>
        <output>
        <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:examples:helloservice" use="encoded"/>
        </output>
    </operation>
</binding>
<service name="Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port binding="tns:Hello_Binding" name="Hello_Port">
    <soap:address location="http://perl.qlc.net/math.pl"/>
</port>
</service>
</definitions>

soap_client.plを実行すると、次のエラーが発生します。初期化されていない値$ resultを使用すると、soap_client.plの6行目で印刷されます。

4

2 に答える 2

3

この問題は、math.wsdlを変更することで解決されました。変更された math.wsdl

<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="urn:Arithmetic" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="HelloService" targetNamespace="urn:Arithmetic" xmlns:y="urn:Arithmetic">
<message name="addRequest">
    <part name="operand1" type="xsd:float" />
    <part name="operand2" type="xsd:float" />
</message>
<message name="addResponse">
    <part name="response" type="xsd:float" />
</message>
<portType name="Hello_PortType">
    <operation name="add">
        <input message="tns:addRequest"/>
        <output message="tns:addResponse"/>
    </operation>
</portType>
<binding name="Hello_Binding" type="tns:Hello_PortType">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="add">
        <soap:operation soapAction="urn:Arithmetic#add"/>
        <input>
            <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Arithmetic" use="encoded"/>
        </input>
        <output>
        <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Arithmetic" use="encoded"/>
        </output>
    </operation>
</binding>
<service name="Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port binding="tns:Hello_Binding" name="Hello_Port">
    <soap:address location="http://perl.qlc.net/math.pl"/>
</port>
</service>
</definitions>
于 2013-02-08T12:48:38.173 に答える
1

結果を取得するには、resultメソッドを含める必要があります。

$client->add(10, 20)->result;

さらに、結果を使用する前に、コマンドが成功したかどうかを確認するために、エラー処理を追加する必要があります。

my $added = $client->add(10,20);
unless (defined $added)
{
    die "Failed add: $!";
}
$result = $added->result;

また、万が一.netサーバーを使用していますか?Soap::Liteドキュメントは、その場合にいくつかの特定の推奨事項を作成し、上記の形式を使用しないことを推奨しています。

于 2013-02-08T09:46:27.640 に答える