0
我遵循client和server教程來創建簡單的客戶端服務器Calculator
Web服務,該服務執行兩個int
的簡單添加。我所有的課程都是由Intelliji自動生成的。Axis IllegalArgumentException,但soap消息正確
當我運行的客戶端,我得到:
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>
這裏是我Calculator
類:
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內置函數生成,如Generate WSDL from Java Code
和Generate Java Code from WSDL
。
下面是客戶端測試的代碼:
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示例。一切似乎都對。我沒有更改任何默認設置。
也可以粘貼WSDL。 –
剛剛添加:) – user5365075
這可能是序列器/解串器沒有正確設置或聲明的問題? Axis在默認情況下會處理字符串,但不處理Integer會很奇怪... – user5365075