dpbtbcz6650 2015-11-02 11:02
浏览 108

Perl SOAP :: Lite修复XML以与PHP SoapClient生成的兼容

How can I make SOAP::Lite produce XML like PHP SoapClient does?

Example

Perl code:

#!/usr/bin/perl
use strict;
use warnings;

use SOAP::Lite on_action => sub{sprintf '%s', $_[0]};
SOAP::Lite->import(+trace => "all");
my $client =  SOAP::Lite->new;

$client->service("https://www.just-example.test/dir/JustTest/Service.asmx?WSDL");
$client->proxy("https://www.just-example.test/dir/JustTest/Service.asmx");
$client->uri("http://example.test/ExampleMethod");

my %params = (
    'TestParam' => "",
     );
$client->ExampleMethod(\%params);

XML that is sent by the Perl code (seems to be not compatible with the service):

<?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>
        <ExampleMethod
            xmlns="http://example.test/ExampleMethod">
            <c-gensym3>
                <TestParam xsi:type="xsd:string" />
            </c-gensym3>
        </ExampleMethod>
    </soap:Body>
</soap:Envelope>

PHP code:

<?php
$client = new SoapClient("https://www.just-example.test/dir/test/JustTest/Service.asmx?WSDL",
        array(
        'trace' => 1,
        'uri' => "http://example.test/ExampleMethod"

         )
);
$params = array (
    'TestParam' => ""
        );

$response = $client->ExampleMethod($params);

echo $client->__getLastRequest() . "
";

var_dump($response);

XML that is sent by the PHP code (seems to be compatible with the service):

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns1="http://example.test/">
    <SOAP-ENV:Body>
        <ns1:ExampleMethod>
            <ns1:TestParam>0</ns1:TestParam>
        </ns1:ExampleMethod>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
  • 写回答

2条回答 默认 最新

  • duanposhi3641 2015-11-02 12:26
    关注

    You have to just change the prefix of the xml accordingly with your specification, take a look at similar question here for more information .

    To solve you particular problem I think you only need to put the following code at the very begining of your code (before setting the wsdl in SOAP::Lite) :

    $SOAP::Constants::PREFIX_ENV = 'SOAP-ENV';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?