在
上一篇文章中的问题,今天又再试了下,居然解决了,看来把遇到问题放一放是有好处的。
第一,是要用对CXF的库,在一行代码未变的情况下,只要使用最新的库。看来在最新库里解决了数组问题:
2.1-incubator-SNAPSHOT
就没问题,如果是用:
2.0-incubator
就会出现上篇文章的情况。我使用MAVEN2,就写成:
<!--for cxf-->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.1-incubator-SNAPSHOT</version>
<!-- version>2.0-incubator</version-->
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.1-incubator-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-databinding-aegis</artifactId>
<version>2.1-incubator-SNAPSHOT</version>
</dependency>
第二,对SOAP::Lite的改变,SOAP::Lite不支持doc/literal,但通过阅读
"NET-based Web Service Using the SOAP::Lite Perl Library".
我的上篇文章有链接,我写的PERL程序在某些情况下依然不行。
这次再加了两处改动后就可以了:(注意:CXF里不要使用aegisDatabinding,用默认的即可)
my $soap = SOAP::Lite
-> uri('http://magic.nms.exchangebit.com/')
-> on_action( sub{ join '/', 'http://www.alfredbr.com', $_[1] })
-> proxy('http://127.0.0.1:8080/ebnms/NotifyService')
->autotype(0);
其中的autotype(0)非常重要。另外一处改动是,程序中的根变量名改成"arg0",即与WSDL中定义一致。
实验发现,带不带attr中的xmlns都可以。完整代码如下:
use SOAP::Lite ( +trace => all, maptype => {} );
my $soap = SOAP::Lite
-> uri('http://magic.nms.exchangebit.com/')
-> on_action( sub{ join '/', 'http://www.alfredbr.com', $_[1] })
-> proxy('http://127.0.0.1:8080/ebnms/NotifyService')
->autotype(0);
#$soap->sendAlarmString ("good");
#$soap->sendAlarm (SOAP::Data->name(arg0=>{devName=>"hehe", devIp=>"ip1"}));
{# call send alarm
my @params = (
# $header,
SOAP::Data->name(arg0 => goodhehe)
);
my $method = SOAP::Data->name('ns1:sendAlarmString')
->attr({"xmlns:ns1" => 'http://magic.nms.exchangebit.com/'});
my $result = $soap->call($method => @params);
print "\nsend string alarm result:\n";
if ($result->fault)
{
print $result->faultstring;
}
else
{
print $result->result;
}
print "\nn";
}
{# call send dev alarm
my @params = (SOAP::Data->name(arg0=>{devName=>"hehe", devIp=>"ip1"}));
my $method = SOAP::Data->name('sendAlarm');
# ->attr({"xmlns:ns1" => 'http://magic.nms.exchangebit.com/'});
my $result = $soap->call($method => @params);
print "\nsend string alarm result:\n";
if ($result->fault)
{
print $result->faultstring;
}
else
{
print $result->result;
}
print "\n\n";
}
{# call send arr alarm
my @params = (
SOAP::Data->name(arg0 => [
{devName=>"hehe1", devIp=>"ip1"},
{devName=>"hehe1", devIp=>"ip1"},
{devName=>"hehe1", devIp=>"ip1"},
{devName=>"hehe1", devIp=>"ip1"},
{devName=>"hehe1", devIp=>"ip1"},
{devName=>"hehe1", devIp=>"ip1"},
{devName=>"hehe1", devIp=>"ip1"},
{devName=>"hehe1", devIp=>"ip1"},
{devName=>"hehe1", devIp=>"ip1"},
{devName=>"hehe1", devIp=>"ip1"},
{devName=>"hehe2", devIp=>"ip2"}])
);
my $method = SOAP::Data->name('sendAlarmArr');
my $result = $soap->call($method => @params);
print "\nsend string alarm result:\n";
if ($result->fault)
{
print $result->faultstring;
}
else
{
my @a = @{$result->result->{item}};
foreach $i (@a) {
print "ele: $i->{devName}, $i->{devIp}\n";
}
}
print "\n\n";
}
posted on 2007-08-23 14:13
我爱佳娃 阅读(1414)
评论(1) 编辑 收藏 所属分类:
Perl 、
web技术