我有问题调用java端点(下面的代码)从perl客户端(activePerl 5.16)。这些代码片段来自《Java Web Services Up And Running》
package ch01.ts;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
@WebService
@SOAPBinding(style=Style.RPC)
public interface TimeServer {
@WebMethod
String getTimeAsString();
@WebMethod
long getTimeAsElapsed();
}
package ch01.ts;
import java.util.Date;
import javax.jws.WebService;
@WebService(endpointInterface="ch01.ts.TimeServer")
public class TimeServerImpl implements TimeServer {
public String getTimeAsString() {
return new Date().toString();
}
public long getTimeAsElapsed() {
return new Date().getTime();
}
}
package ch01.ts;
import javax.xml.ws.Endpoint;
public class TimeServerPublisher {
public static void main(String[] args) {
Endpoint.publish("http://127.0.0.1:9876/ts", new TimeServerImpl());
}
}
和perl消费者:
use SOAP::Lite;
my $url = 'http://127.0.0.1:9876/ts?wsdl';
my $service = SOAP::Lite->service($url);
print "nCurrent time is: ",$service->getTimeAsString();
print "nElapsed miliseconds from the epoch: ", $service->getTimeAsElapsed();
当我调用web服务时,我有这个堆栈跟踪:
maj 04, 2013 10:21:40 AM com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit handle
SEVERE: Couldn't create SOAP message. Expecting Envelope in namespace http://schemas.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/envelope/, but got http://schemas.xmlsoap.org/wsdl/soap/
at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(Unknown Source)
我认为soap版本是问题所在,上面的例子是从1.1开始的,当我将客户端代码更改为
时my $service = SOAP::Lite->service($url)->soapversion('1.2');
则抛出不同的错误
com.sun.xml.internal.ws.server.UnsupportedMediaException: Unsupported Content-Type: application/soap+xml; charset=utf-8 Supported ones are: [text/xml]
我需要帮助处理信封问题或内容类型。我将感激任何指示,代码和任何其他可能帮助。
我不太确定Perl->Soap API,但对于客户端版本为1.1的第一种情况,您可能需要在某处提到名称空间。
可能像
server->setNamespace() //or
SOAP::Lite->service($url,"<namespace>"); //please search for perl web service client examples
对于第二种情况(1.2)服务是期待文本和你的api发送soap编码或其他东西。
引用http://www.herongyang.com/Web-Services/Perl-SOAP-1-2-Unsupported-Media-Type-application-soap.html
这可能有帮助
my $client = SOAP::Lite->new()
->soapversion('1.2')
->envprefix('soap12')
->default_ns('http://xmlme.com/WebServices')
->on_action( sub {join '/', @_} )
->readable(true)
->proxy('http://www.xmlme.com/WSShakespeare.asmx');
和
http://www.herongyang.com/web services/perl - soap - 1 - 2 -请求-差异- soap - 1 - 1 -和- 1 - 2. - html
希望有所帮助