【问题标题】:Java endpoint - perl consumer web serviceJava 端点 - perl 消费者 Web 服务
【发布时间】:2013-04-28 16:05:06
【问题描述】:

我从 perl 客户端(activePerl 5.16)调用 java 端点(下面的代码)有问题。 这些代码 sn-ps 来自《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]

我在处理信封问题或内容类型方面需要帮助。我将不胜感激任何指示、代码和其他任何可以提供帮助的东西。

【问题讨论】:

    标签: java web-services perl


    【解决方案1】:

    我不太确定 Perl->Soap API,但对于客户端版本为 1.1 的第一种情况,您可能还需要在某处提及命名空间。

    可能是这样的

    server->setNamespace() //or
    SOAP::Lite->service($url,"<namespace>"); //please search for perl web service client         examples
    

    对于第二种情况(1.2),服务需要文本,而您的 api 发送肥皂编码或其他东西。

    参考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-Request-Differences-SOAP-1-1-and-1-2.html

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2015-09-22
      • 1970-01-01
      • 1970-01-01
      • 2017-09-18
      • 1970-01-01
      • 2016-03-17
      • 1970-01-01
      • 2023-01-16
      • 1970-01-01
      相关资源
      最近更新 更多