当Perl的SOAP :: Lite模块查询时,Java JAX-WS服务返回SOAP错误

时间:2011-11-05 19:01:34

标签: java perl soap jax-ws

我有一个简单的Java服务来获取当前时间。

我写了一个Perl客户端来访问它。

#! /usr/bin/perl -w
use SOAP::Lite;
my $url = 'http://127.0.0.1:9876/ts?wsdl';
my $service = SOAP::Lite->service($url)->soapversion('1.1');

print "\nCurrent time is: ", $service->getTimeAsString();
print "\nElapsed milliseconds from the epoch: ", $service->getTimeAsElapsed();

一旦客户端进行调用(也在同一台机器上),服务就会记录下面的异常,并将SOAP错误返回给客户端而不是预期的响应。

Nov 05, 2011 11:20:34 AM com.sun.xml.internal.ws.transport.http.HttpAdapter$Http Toolkit handle
SEVERE: Couldn't create SOAP message. Expecting Envelope in namespace http://sch
emas.xmlsoap.org/soap/envelope/, but got http://schemas.xmlsoap.org/wsdl/soap/
com.sun.xml.internal.ws.protocol.soap.VersionMismatchException: Couldn't create
SOAP message. Expecting Envelope in namespace http://schemas.xmlsoap.org/soap/en
velope/, but got http://schemas.xmlsoap.org/wsdl/soap/
at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCod ec.java:167)
at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCod ec.java:292)
at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCod ec.java:118)
at com.sun.xml.internal.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:343)
at com.sun.xml.internal.ws.transport.http.HttpAdapter.decodePacket(HttpAdapter.java:321)
at com.sun.xml.internal.ws.transport.http.HttpAdapter.access$400(HttpAdapter.java:81)
at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:576)
at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(WSHttpHandler.java:95)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(WSHttpHandler.java:80)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)
at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:80)
at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:665)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)
at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:637)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

知道为什么吗?

2 个答案:

答案 0 :(得分:2)

有点晚了,但对于遇到此问题的其他人来说,问题是SOAP :: Lite盲目地从WSDL文件导入名称空间并根据其中使用的前缀覆盖自己的名称空间,包括它使用的名称空间发送SOAP信封本身。

解决方案是使用envprefix方法使其为SOAP Envelope使用不同的名称空间前缀。例如:

my $service = SOAP::Lite->service($url)->soapversion('1.1')->envprefix('S');

答案 1 :(得分:0)

您的客户端Python正在以与您的Java Web服务所期望的格式不同的格式发送XML。为了查看真正发送客户的内容,我建议您使用以下工具

http://code.google.com/p/tcpmon/

它可以让您检查发送的XML并根据需要进行修改。这是一个关于如何使用TcpMon的教程

http://ws.apache.org/commons/tcpmon/tcpmontutorial.html