这是要访问的NET的WebService及其中一个方法DataSendUp
http://192.168.1.222/SSServices/DataService.asmx?op=DataSendUp
E:\webservice\axis2-1.6.2-bin\axis2-1.6.2\bin>wsdl2java -p org.webclient.service
-uri http://192.168.1.222/SSServices/DataService.asmx?wsdl//说明这里-p 后面是指包名
-uri 后面是wsdl 文件路径名
最后:用命令生成客户端代码
DataServiceCallbackHandler.java DataServiceStub.java
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import java.io.File;
import java.io.IOException;
/**
* ********************************************************
* Module Name: AXIS2 Webservice
* Function Desc:
* Create Date: 12-9-20
* Creator:lige
* remark:
* **********************************************************
*/
public class WebClient {
private String soapaction = "http://tempuri.org/DataSendUp"; //域名,这是在server定义的
/***
*
* @param file 传入的文件对象
* @param urlip 传入url的ip地址
* @param account DataSendUp的account
* @param urlname DataSendUp的name
* @return DataServiceStub的getDataSendUpResult()方法
* @throws RemoteException
*/
public static String getService(File file,String urlip,String account,String urlname) throws RemoteException {
String url = "http://"+urlip+"/SSServices/DataService.asmx";
DataServiceStub ser = new DataServiceStub(url);
DataServiceStub.DataSendUp dataSendUp20 = new DataServiceStub.DataSendUp();
dataSendUp20.setAccount(account);
dataSendUp20.setName(urlname);
FileDataSource dataSource = new FileDataSource(file);
DataHandler data=new DataHandler(dataSource);
dataSendUp20.setData(data);
DataServiceStub.DataSendUpResponse obj = ser.dataSendUp(dataSendUp20);
return obj.getDataSendUpResult();
}
public static void main(String args[]) throws IOException {
String url = "http://192.168.1.222/SSServices/DataService.asmx";
DataServiceStub ser = new DataServiceStub(url);
DataServiceStub.DataSendUp dataSendUp20 = new DataServiceStub.DataSendUp();
dataSendUp20.setAccount("222");
dataSendUp20.setName("wxb");
File file=new File("F:\\1.xls");
FileDataSource dataSource = new FileDataSource(file);
DataHandler data=new DataHandler(dataSource);
dataSendUp20.setData(data);
DataServiceStub.DataSendUpResponse obj = ser.dataSendUp(dataSendUp20);
System.out.println("-----------" + obj.isDataSendUpResultSpecified());
System.out.println("-----------" + obj.getDataSendUpResult());
}
}
需要调用到AXIS2的以下包:activation-1.1.jar axiom-api-1.2.13.jar axiom-impl-1.2.13.jar axis2-adb-1.6.2.jar axis2-adb-codegen-1.6.2.jar axis2-codegen-1.6.2.jar
axis2-java2wsdl-1.6.2.jar axis2-kernel-1.6.2.jar commons-codec-1.3.jar commons-httpclient-3.1.jar wsdl4j-1.6.2.jar wstx-asl-3.2.9.jar XmlSchema-1.4.7.jar neethi-3.0.2.jar axis2-transport-http-1.6.2.jar axis2-transport-local-1.6.2.jar httpcore-4.0.jar