加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

从SOAP :: Lite迁移到XML :: Compile :: SOAP

发布时间:2020-12-16 22:49:18 所属栏目:百科 来源:网络整理
导读:所以这是我的 SOAP::Lite 代码 #!/usr/bin/perluse 5.006;use strict;use warnings;use SOAP::Lite +trace = [ 'debug' ];my $req1 = SOAP::Lite-new( readable = 1,autotype = 0,proxy = 'https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor',)
所以这是我的 SOAP::Lite代码

#!/usr/bin/perl
use 5.006;
use strict;
use warnings;
use SOAP::Lite +trace => [ 'debug' ];

my $req1 = SOAP::Lite->new(
    readable => 1,autotype => 0,proxy    => 'https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor',);

$req1->requestMessage(
    SOAP::Data->new(
        name => 'item',attr => { foo => '0' },value => SOAP::Data->new(
            name => 'foo',value => 1,),);

它生成这个XML

<?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>
<requestMessage>
  <c-gensym9>
    <item foo="0">
      <foo>1</foo>
    </item>
  </c-gensym9>
</requestMessage>
</soap:Body>
</soap:Envelope>

如何使用XML::Compile::SOAP生成相同的东西(没有gensym)?

解决方法

尝试

cpan BERLE/SOAP-Simple-0.00_03.tar.gz

然后

#!/usr/bin/perl --
use strict; use warnings;
use Data::Dumper;
use SOAP::Simple;
my $wsdlfile = '...';
my $soap = SOAP::Simple->new($wsdlfile);
print Dumper(
    $soap->requestMessage(
        item => [
            { foo => 1  },],)
);

或者查看http://cpansearch.perl.org/src/MARKOV/XML-Compile-SOAP-2.24/t/53wsdlrpclit.t并复制http://cpansearch.perl.org/src/MARKOV/XML-Compile-SOAP-2.24/t/examples/rpc-literal/element.pl并使用

schema2example -s element.wsdl -s type.wsdl -x requestMessage.xml

为element.pl生成一个%请求,所以最后你会得到类似的东西

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

# general debugging of XML::Compile modules
#~ use Log::Report mode => 3;

# Data::Dumper is your friend in understanding the answer
use Data::Dumper;
$Data::Dumper::Indent = 1;

# The features we use
use XML::Compile::WSDL11;
use XML::Compile::SOAP11;
use XML::Compile::Transport::SOAPHTTP;  # we fake an HTTP server

#
# During initiation 'compile time'
#

my $wsdl = XML::Compile::WSDL11->new('element.wsdl');
my $call = $wsdl->compileClient('using_element'
#~,transport_hook => &;fake_server # hook simulates a remote server at test
  );

#
# Reuse often at 'run time'
#

my %request =
 ( item =>
   [ { foo => 1}
   ]
 );

my $answer = $call->( requestMessage => %request);

# Useful for debugging.  Also useful to report to syslog
#    my ($answer,$trace) = $call->(%request);
#    $trace->printTimings;

# When you do not know how the answer is structured
#print Dumper $answer;

if($answer->{Fault})
{   print "Oopsn";
}
else
{   print "*** RESULT=$answer->{answer_via_element}{result}n";
}

exit 0;

一旦你生成了你想要的xml,就试试吧

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读