一、根据约定条件生成客户端
1.需要axis.jar包
2.调用
import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.XMLType; public static void main(String[] args)(String param1, Date param2, double param3) { String url = "http:IP:PORT/url" ; try { Service service = new Service(); Call call = (Call) service.createCall(); //调用的url地址 call.setTargetEndpointAddress(url); //调用的方法名 call.setOperationName( "doService" ); //参数,有几个写几个,类型对应 call.addParameter( "parameter1" ,org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN ) ; call.addParameter( "parameter2" ,org.apache.axis.encoding.XMLType.XSD_DATE,javax.xml.rpc.ParameterMode.IN ) ; call.addParameter( "parameter3" ,org.apache.axis.encoding.XMLType.XSD_DOUBLE,javax.xml.rpc.ParameterMode.IN ) ; //返回值类型
call.setReturnType(XMLType.XSD_STRING );
call.setUseSOAPAction( true );
//对应的参数 String result = (String) call.invoke( new Object[]{param1,param2,param3}) ; } catch (javax.xml.rpc.ServiceException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } }
二、根据wsdl文件生成客户端
public static void main(String[] args) { //访问webservice的地址 String url = "http://IP:PORT/url" ; try { XXXBindingStub binding; binding = (XXXBindingStub)new XXXLocator().getXXXHttpSoap11Endpoint(new java.net.URL(url)); //参数 String result = binding.send( "param", "param", "param"); //结果 System. out.println(result); } catch (MalformedURLException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } }
原文:http://www.cnblogs.com/zcrutherford/p/5163875.html