SOAP API中对象方法的调用无效

时间:2014-08-19 17:31:40

标签: perl soap request

Perl代码:

sub exec_cmd {

   use strict 'refs';

   my $self = shift @_;
   my $cmd  = shift @_;

   die 'Invalid call of the object method' unless ref $self;
   die 'Command not specified' unless $cmd;
   die 'Connection to SQL server not defined, use connect method first' unless $$self{'sql_pipe'};

   print { $$self{'sql_pipe'}; } $cmd . "\n";

   return 1;
}

我对API的请求:

POST /xml HTTP/1.1

Content-Length: 452
TE: deflate,gzip;q=0.3
Connection: TE, close
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Host: 127.0.0.1
User-Agent: SOAP
Content-Type: text/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:namesp13="SQL">
    <soap:Body>
        <namesp13:exec_cmd>MY SQL QUERY</namesp13:exec_cmd>
    </soap:Body>
</soap:Envelope>

输出

<?xml version="1.0" encoding="UTF-8"?><soap:Envelope         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"     xmlns:xsd="http://www.w3.org/2001/XMLSchema"     soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault>    <faultcode>soap:Server</faultcode><faultstring>Invalid call of the object method at SQL.pm     line 24.
</faultstring></soap:Fault></soap:Body></soap:Envelope>

我的问题是,¿如何在exec_cmd中输入要执行的参数?我尝试使用以下XML但它不起作用。

<namesp13:exec_cmd>MY SQL QUERY</namesp13:exec_cmd>

1 个答案:

答案 0 :(得分:0)

除非您向我们提供API的详细信息,否则无法告知如何编码SOAP查询。通常,请求的参数在命令内的辅助元素中是预期的。比如这样

<namesp13:exec_cmd xmlns:namesp13="http://www.example.org/interface">
  <namesp13:sql>MY SQL QUERY</namesp13:sql>
  <namesp13:param1>parameter one</namesp13:param1>
</namesp13:exec_cmd>