0

我正在尝试使用 SOAP::Lite 模块进行简单的 API 调用(至少这是我开始时的想法)。我在这里使用公开可用的 SOAP API 之一来添加两个数字。我收到以下错误:

服务器无法识别 HTTP Header SOAPAction: http://tempuri.org/#Add的值。

我在 SOAP::Lite 中启用了调试,看来我的请求格式不正确。我怀疑 intA 和 intB 中指定的类型 (xsi:type="xsd:int") 引起了问题。

调试请求:

<?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:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">   
  <soap:Body>
    <Add xmlns="http://tempuri.org/">
      <intA xsi:type="xsd:int">5</intA>
      <intB xsi:type="xsd:int">10</intB>
    </Add>   
 </soap:Body> </soap:Envelope>

这是我的 Perl 代码:

#!/usr/bin/env perl

use strict;
use warnings;
use SOAP::Lite;
#use SOAP::Lite +trace => 'all';    

    SOAP::Lite->import(trace => 'debug');

    #my $uri = 'http://tempuri.org/';
    my $proxy = 'http://www.dneonline.com/calculator.asmx';
    my $ns = 'http://tempuri.org/'; 

    my $client = SOAP::Lite
            ->readable(1)
            ->uri($ns)
            ->proxy($proxy);

    my $param1 = SOAP::Data->name("intA" => $x);
    my $param2 = SOAP::Data->name("intB" => $y);

    my $response = $client->Add($param1,$param2);

    print "Result is $response \n";

注意:我尝试在 SOAPUI 工具中加载 WSDL,并且 API 在那里工作正常。

更新

正如@simbabque 建议的那样,我尝试使用 LWP::ConsoleLogger 进行调试

标题如下所示:

.---------------------------------+-----------------------------------------.
| Request (before sending) Header | Value                                   |
+---------------------------------+-----------------------------------------+
| Accept                          | text/xml, multipart/*, application/soap |
| Content-Length                  | 549                                     |
| Content-Type                    | text/xml; charset=utf-8                 |
| SOAPAction                      | "http://tempuri.org/#Add"               |
| User-Agent                      | SOAP::Lite/Perl/1.27                    |
'---------------------------------+-----------------------------------------'

我不知道#是从哪里来的。也许我会尝试 SOAP::Simple 看看它是否有帮助。

干杯

4

1 回答 1

0

将URI 和方法名称 ( Add) 连接起来构建一个名为 SOAPAction 的 http 标头。

URI 必须以“/”结尾。SOAP::Lite 用“#”合并它们。

很久以前我遇到了同样的问题。发现基于 .NET 的 Web 服务对看到“#”感到失望,并通过简单连接 URI 和方法名称的 on_action 处理程序从手册页中阅读了有关此解决方案的信息。所有这些都在 man SOAP::Lite 中有详细记录

my $client = SOAP::Lite->new(
  readable => 1,
  # uri is the same as package/class name into cgi file; must end with "/"
  uri => $ns, 
  # on action corrects SOAPAction to make .NET happy. .NET dislike the '#' 
  # $_[1] will contain method name on $client->call('someMethName')
  on_action => sub { return '"'. $ns . $_[1] .'"'; },  
  # proxy is the full resource URL of aspx/php/cgi/pl wich implements method name 
  proxy => $proxy);
# rest of your code...
于 2018-10-10T09:14:14.500 回答