|
我需要调用 Webservice , 要引进这两个文件:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
请问在Wex5中这样用没有问题吧?
java代码如下:
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.justep.common.MessageUtils;
import com.justep.ui.system.UISystemMessages;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class ImageUp extends com.justep.ui.impl.JProcessorImpl {
private static String SAVE_PATH = "concat('justep_public/',currentPersonID(),'/image')";
private static int MAX_SIZE = 2000;//单位KB
protected void doPost(HttpServletRequest request,HttpServletResponse response)
throws IllegalStateException, IOException{
response.setContentType("text/html;charset=UTF-8");
// 转型为MultipartHttpRequest:
MultipartHttpServletRequest multipartRequest=(MultipartHttpServletRequest) request;
//传送数据到webservice
Service sv = new Service(); //new 一个服务
Call call = (Call) sv.createCall(); //创建一个call对象
call.setTargetEndpointAddress(new URL("http://localhost:2080/WebService/MyService.asmx")); //设置要调用的接口地址以上一篇的为例子
call.setOperationName(new QName("uploadImageData")); //设置要调用的接口方法
call.addParameter("ImageData", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);//设置参数名 id 第二个参数表示String类型,第三个参数表示入参
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//返回参数类型
//开始调用方法,假设我传入的参数id的内容是1001 调用之后会根据id返回users信息,以xml格式的字符串返回,也可以json格式主要看对方用什么方式返回
String result = (String) call.invoke(new Object[]{imagedata});
//String result = JSON.toJSONString(rui);//这边就是为了返回给UEditor做的格式转换
response.getWriter().write(result);
return null;
}
|
|