当前位置: 代码迷 >> Web前端 >> webservice容易调用
  详细解决方案

webservice容易调用

热度:99   发布时间:2012-12-21 12:03:49.0
webservice简单调用
import java.io.FileOutputStream;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class MyWebServices

{

private String url = "http://localhost:8080/webServiceTest/services/wssTest";//提供接口的地址

private String soapaction = "http://tempuri.org/"; //域名,这是在server定义的

public MyWebServices(){
String pathStr = "D:\\test\\1.xlsx";
Service service = new Service();
try {
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(url);
call.setOperationName(new QName(soapaction, "readFile")); //设置要调用哪个方法
call.addParameter(new QName(soapaction, "pathStr"), //设置要传递的参数
org.apache.axis.encoding.XMLType.XSD_STRING,

call.setReturnType(new QName(soapaction, "readFile"),
byte[].class); //要返回的数据类型(自定义类型)
byte[] bytes = (byte[])call.invoke(new Object[] {pathStr});
FileOutputStream fos = new FileOutputStream("D:\\test\\11.xlsx");
fos.write(bytes);
fos.close();
} catch (Exception ex){
ex.printStackTrace();
}
}
public static void main(String args[]){
new MyWebServices();
}
//备注:org.apache.axis.encoding.XMLType.XSD_STRING 参数类型,可以int,float等
  相关解决方案