Perl客户端到JAX-WS java服务器问题

时间:2011-07-22 23:06:30

标签: java perl soap jax-ws soaplite

我有一个发布网络服务的JAX-WS java服务器

@WebService(endpointInterface="calculator.operation.Calculator")
public class CalculatorWs implements Calculator{

public String[] add(String a) {

    System.out.println(a);

    String[] test = {"this", "that"};
    System.out.println(test);
    return test;
}

}

@WebService
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT)
public interface Calculator {
    String[] add(String a);
}

并拥有一个perl客户端

use SOAP::Lite +trace => 'all';
$SOAP::Constants::PREFIX_ENV = 'soapenv';
$SOAP::Constants::PREFIX_ENC = "SOAP-ENC";
my $soap = SOAP::Lite
->service('http://localhost:8080/tomcat/calculator?wsdl')
->soapversion('1.1');
my $var = {'a' => "test"};
my $result = $soap -> add($var);

我遇到的问题是Java服务器没有收到Perl客户端传递的参数,尽管客户端接收并识别Java服务器返回的值。

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsam="http://www.w3.org/2
007/05/addressing/metadata" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/
policy" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="ht
tp://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://operation.calculator/
" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soapenv:Body><tns:add><c-gensym3
><a xsi:type="xsd:string">test</a></c-gensym3></tns:add></soapenv:Body></soapenv
:Envelope>

这是Perl客户端发送的SOAP请求。我假设它的构建SOAP请求的方式是责备。但如果有人能帮助我解决这个问题,我将不胜感激。感谢。

(编辑) 这是JAX-WS生成的WSDL:

<?xml version="1.0" encoding="UTF-8" ?> 
- <!--  Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.3-b01-. 
--> 
- <!--  Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.3-b01-. 
  --> 
- <definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-    wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy"    xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy"  xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://operation.calculator/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://operation.calculator/" name="CalculatorWsService">
- <types>
- <xsd:schema>
<xsd:import namespace="http://operation.calculator/" schemaLocation="http://localhost:8080/tomcat/calculator?xsd=1" /> 
</xsd:schema>
</types>
- <message name="add">
 <part name="parameters" element="tns:add" /> 
</message>
- <message name="addResponse">
<part name="parameters" element="tns:addResponse" /> 
</message>
- <portType name="Calculator">
- <operation name="add">
<input wsam:Action="http://operation.calculator/Calculator/addRequest" message="tns:add" /> 
<output wsam:Action="http://operation.calculator/Calculator/addResponse" message="tns:addResponse" /> 
</operation>
</portType>
- <binding name="CalculatorWsPortBinding" type="tns:Calculator">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> 
- <operation name="add">
<soap:operation soapAction="" /> 
- <input>
<soap:body use="literal" /> 
</input>
- <output>
<soap:body use="literal" /> 
</output>
</operation>
</binding>
- <service name="CalculatorWsService">
- <port name="CalculatorWsPort" binding="tns:CalculatorWsPortBinding">
<soap:address location="http://localhost:8080/tomcat/calculator" /> 
</port>
</service>
</definitions>

2 个答案:

答案 0 :(得分:0)

显示java函数非常适合java程序员,你需要显示WSDL或示例SOAP(读取XML)调用...我的猜测,你需要的一切

my $result = $soap -> add( 'test');

你应该知道SOAP :: Simple在wsdl上比SOAP :: Lite

更好

答案 1 :(得分:0)

我遇到了同样的问题。我使用了以下两个更改:

  1. 将您的参数命名为XSD(http://localhost:8080/tomcat/calculator?xsd=1
  2. 不要使用默认命名空间,而是使用SOAP方法的命名空间前缀(ns()方法)。
  3. 示例代码:

    my $soap = SOAP::Lite                                             
      -> proxy('http://localhost:8080/tomcat/calculator')
      -> ns   ('http://operation.calculator/');
    
    my $response = $soap->call('add', SOAP::Data->name( arg0 => 'Peter Pan'));
    
相关问题