gpt4 book ai didi

java - 轴 IllegalArgumentException 但 SOAP 消息是正确的

转载 作者:行者123 更新时间:2023-12-01 09:57:26 25 4
gpt4 key购买 nike

我关注了clientserver创建一个简单的客户端-服务器计算器 Web 服务的教程,该服务执行两个 int 的简单加法。我所有的类都是由 Intelliji 自动生成的。

当我运行客户端时,我得到:

AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.generalException
faultSubcode:
faultString: Tried to invoke method public int calculator.Calculator.add(int,int) with arguments java.lang.Integer,null. The arguments do not match the signature.; nested exception is:
java.lang.IllegalArgumentException
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}hostname:unknown

但是 SOAP 请求是正确的:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<a xmlns="http://calculator">1</a>
<b xmlns="http://calculator">7</b>
</soapenv:Body>
</soapenv:Envelope>

这是我的计算器类:

package calculator;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public class Calculator {

@WebMethod
public int add(int a, int b) {
return a + b;
}

}

所有代码均由 Intelliji 内置函数生成,例如从 Java 代码生成 WSDL从 WSDL 生成 Java 代码

这是客户端测试代码:

package calculator;

import javax.xml.rpc.ServiceException;
import java.rmi.RemoteException;

public class Test {

public static void main(String[] args) {

CalculatorService serviceLocator = new CalculatorServiceLocator();

Calculator_PortType service = null;
try {
service = serviceLocator.getCalculator();
} catch (ServiceException e) {
e.printStackTrace();
throw new RuntimeException("Something went wrong");
}

try {
int add = service.add(1,7);
System.out.println("add: " + add);

} catch (RemoteException e) {
e.printStackTrace();
}
}
}

这是 WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://calculator" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://calculator" xmlns:intf="http://calculator" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema elementFormDefault="qualified" targetNamespace="http://calculator" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="a" type="xsd:int"/>
<element name="b" type="xsd:int"/>
<element name="addReturn" type="xsd:int"/>
</schema>
</wsdl:types>
<wsdl:message name="addResponse">
<wsdl:part element="impl:addReturn" name="addReturn"/>
</wsdl:message>
<wsdl:message name="addRequest">
<wsdl:part element="impl:a" name="a"/>
<wsdl:part element="impl:b" name="b"/>
</wsdl:message>
<wsdl:portType name="Calculator">
<wsdl:operation name="add" parameterOrder="a b">
<wsdl:input message="impl:addRequest" name="addRequest"/>
<wsdl:output message="impl:addResponse" name="addResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CalculatorSoapBinding" type="impl:Calculator">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="add">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="addRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="addResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CalculatorService">
<wsdl:port binding="impl:CalculatorSoapBinding" name="Calculator">
<wsdlsoap:address location="http://localhost:8080/services/Calculator"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

SOAP 请求正确。我有一个运行良好的 Hello World 示例。一切似乎都是对的。我没有更改任何默认设置。

最佳答案

公开类 (1) 并生成 WSDL 文件 (2) 时,请确保使用 wrapped 样式而不是 document

关于java - 轴 IllegalArgumentException 但 SOAP 消息是正确的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37081694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com