我在用axis2-1.6.2制作客户端时遇到了问题,然后我总结了这个问题。
我正在尝试使用下一个wsdl来创建一个客户端:http://www.mobilefish.com/services/web_service/countries.php?wsdl
我在windows中使用这行:
WSDL2Java.bat -uri http://www.mobilefish.com/services/web_service/countries.php?wsdl -d xmlbeans -s
我使用xmlbeans,因为使用adb我在方面有问题
当我尝试使用这个客户端与下一个代码:
public static void main(String[] args) throws RemoteException {
CountriesWebserviceMobilefishComServiceStub countriWebService =
new CountriesWebserviceMobilefishComServiceStub("http://www.mobilefish.com/services/web_service/countries.php?wsdl");
CountryInfoByIanaDocument cidocument = CountryInfoByIanaDocument.Factory.newInstance();
CountryInfoByIana ci = CountryInfoByIana.Factory.newInstance();
ci.setIanacode("us");
cidocument.setCountryInfoByIana( ci );
countriWebService.countryInfoByIana( cidocument );
}
我收到下一个错误:
线程"main">org.apache.axis2.AxisFault中出现异常:请求中未指定方法位于org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)网址:org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)网址:org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)网址:org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)网址:org.apache.axis2.client.OperationClient.exexecute(OperationClient.java:165)网址:com.mobilefish.webservice.countriesWebserviceMobileshComServiceStub.countryInfoByIana(CountrysWebservicesMobileshComServicesStub.java:462)在Main.Main(Main.java:33)
如果有人能帮助解决这个问题,我们将不胜感激。提前谢谢。
看起来web服务没有正确发送消息所需的信息。您正在调用RPC/编码样式的web服务,该服务希望通过提供用操作名称包装的消息负载来调用其操作。验证这是否真的发生了,并且原始SOAP消息是否包含操作名称。
另一种可能性是,服务可能需要您填充soap action
标头,以便它能够处理您的请求。填充此http标头并查看会发生什么
我来这里是为了回答我自己的问题,确切地说,我不知道axis2在我使用web服务时会发生什么,在我在这里报告的错误之后,我有很多新的错误,但我可以使用axis1.4来使用web服务的所有操作来解决这个问题。
只是我创建了对象:
java -cp %AXISCLASSPATH% org.apache.axis.wsdl.WSDL2Java http://www.mobilefish.com/services/web_service/countries.php?wsdl
然后我使用下一个代码:
public static void main(String[] args) throws MalformedURLException, RemoteException, ServiceException {
String endpoint = "http://www.mobilefish.com/services/web_service/countries.php?wsdl";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName( "countryInfoByIana" );
call.addParameter( "ianacode", XMLType.XSD_STRING, ParameterMode.IN );
call.setReturnType(XMLType.SOAP_ARRAY);
Object _resp = call.invoke( new Object [] { "us" });
Object[] objetoArray = (Object[]) _resp;
for(int i = 0; i< objetoArray.length; i++){
System.out.println( objetoArray[ i ] );
}
}
也许不可能使用axis2消费web服务,我不知道,但现在我发现了这个对我有效的解决方案。
无论如何,谢谢。