当 Perl 的 SOAP::Lite 模块查询时,Java JAX-WS 服务返回 SOAP 错误
我有一个简单的 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)
知道为什么吗?
I have a simple Java service to get the current time.
I wrote a Perl client to access it.
#! /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();
As soon as the client makes the call (also on same machine) the service logs the exception below and a SOAP fault is returned to the client instead of the expected response.
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)
Any idea why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有点晚了,但对于遇到此问题的其他人来说,问题在于 SOAP::Lite 盲目地从 WSDL 文件导入名称空间,并根据此处使用的前缀覆盖自己的名称空间,包括用于发送消息的名称空间。 SOAP 信封本身。
解决方案是使用 envprefix 方法,使其对 SOAP Envelope 使用不同的名称空间前缀。例如:
my $service = SOAP::Lite->service($url)->soapversion('1.1')->envprefix('S');
A bit late, but for everyone else that is having this issue, the problem is that SOAP::Lite is blindly importing the namespaces from the WSDL file and overwriting its own based on the prefixes used there, including the namespace it uses to send the SOAP Envelope itself.
The solution is to make it use a different namespace prefix for the SOAP Envelope, using the envprefix method. For example:
my $service = SOAP::Lite->service($url)->soapversion('1.1')->envprefix('S');
您的客户端 Python 以与您的 Java Web 服务所期望的格式不同的格式发送 XML。为了查看真正向您的客户端发送的内容,我建议您使用以下工具
http://code. google.com/p/tcpmon/
它可以让您检查发送的 XML 并根据需要进行修改。这是有关如何使用 TcpMon 的教程
http://ws.apache.org/commons/ tcpmon/tcpmontutorial.html
Your client Python is sending the XML in a different format that the expected by your Java Web Service. In order to see what is really sending your client I suggest that you use the following tool
http://code.google.com/p/tcpmon/
It will let you check the XML sended and modify it if you want. Here is a tutorial about how to use TcpMon
http://ws.apache.org/commons/tcpmon/tcpmontutorial.html