2013-05-04 139 views
1

我從perl客戶端(activePerl 5.16)調用java端點(代碼如下)有問題。 這些代碼段是從書的Java Web服務正常運行Java端點 - perl消費者web服務

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) 

我認爲肥皂版本的問題,上面的例子是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] 

我需要要麼信封的問題或內容類型處理幫助。我會很感激任何方向,代碼和其他任何可能的幫助。

回答

0

我不太確定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-Request-Differences-SOAP-1-1-and-1-2.html

希望它可以幫助