2015-11-02 124 views
0

如何使SOAP :: Lite生成XML,如PHP SoapClient所做的那样?Perl SOAP :: Lite修复XML与PHP生成的SoapClient兼容

Perl代码:由Perl代码发送

#!/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(似乎是与该服务兼容):

<?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代码:

<?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() . "\n"; 

var_dump($response); 
0由PHP代码发送

XML(似乎是与该服务兼容):

<?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> 

回答

1

你必须只用你的技术规格改变相应的XML的前缀,看看类似的问题here为更多信息 。

为了解决您特定的问题,我认为你只需要把下面的代码在你的代码非常begining(在SOAP ::精简版设置WSDL前):

$SOAP::Constants::PREFIX_ENV = 'SOAP-ENV'; 
+0

谢谢,我试图改变前缀(还有很多其他的东西) - 这并没有帮助。我无法生成不破坏数据格式的XML。也许有些时候我会花上一两天的时间来彻底学习这个Perl模块,但是现在我已经在PHP中拥有完美的开箱即用的解决方案了。我只会从Perl代码中调用php脚本。 – a1111exe

0

与SOAP代码::建兴很简单:

$uri = 'http://example.test'; 
$proxy = 'https://www.just-example.test/dir/JustTest/Service.asmx'; 

$client = SOAP::Lite->new(
       uri => $uri, 
       proxy => $proxy, 
      ); 

$client->autotype(0); 
$client->readable(1); 
$client->ns($uri,'ns1'); 
$client->envprefix('SOAP-ENV'); 

$params = SOAP::Data->name(TestParam => 0)->prefix('ns1'); 

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