简体   繁体   English

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

[英]Perl client to JAX-WS java server issue

I have a JAX-WS java server which publishes a web-service我有一个发布 Web 服务的 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;
}

}

and

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

and have a perl client并有一个 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);

The problem I'm having is that the Java server does not receive the arguments passed by the Perl client, although the value returned by the Java server is received and recognized by the client. The problem I'm having is that the Java server does not receive the arguments passed by the Perl client, although the value returned by the Java server is received and recognized by the client.

<?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>

this is the SOAP request sent by the Perl client.这是 Perl 客户端发送的 SOAP 请求。 Im assuming the way its building the SOAP request is to blame.我假设它构建 SOAP 请求的方式是罪魁祸首。 But if anyone could help me figure it out, would be greatly appreciated.但如果有人能帮我弄清楚,将不胜感激。 Thanks.谢谢。

(edit) Here is the WSDL generated by JAX-WS: (编辑)这是 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>

I was having the same problem.我遇到了同样的问题。 I made it work with the following two changes:我使它与以下两个更改一起工作:

  1. Name your arguments as in the XSD ( http://localhost:8080/tomcat/calculator?xsd=1 )将您的 arguments 命名为 XSD ( http://localhost:8080/tomcat/calculator?xsd=1 )
  2. Don't use the default namespace, but a namespace prefix for the SOAP method ( ns() method).不要使用默认命名空间,而是使用 SOAP 方法( ns()方法)的命名空间前缀。

Example code:示例代码:

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'));

Showing the java function is great for java programmers, you need to show the WSDL or sample SOAP (read XML) invocation... my guess, all you need Showing the java function is great for java programmers, you need to show the WSDL or sample SOAP (read XML) invocation... my guess, all you need

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

You should know SOAP::Simple is better at wsdl than SOAP::Lite您应该知道 SOAP::Simple 在 wsdl 上优于 SOAP::Lite

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM