1.发布WebService
2.选择发布的方法
3.把生成的代码复制到对应目录
4.文本打开生成的wsdd文件,复制内容
5.粘贴内容到文件server-config.wsdd
6.重启服务器下载wsdl文件
7.修改文件后缀为.wsdl,复制到eclipse工种根目录
8.生成客户端代码
9.配置服务器地址
10.代码调用接口方法
package com.hhxh.weixun.easservice;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import javax.xml.rpc.ServiceException;
import localhost.ormrpc.services.EASLogin.EASLoginProxy;
import localhost.ormrpc.services.EASLogin.EASLoginProxyServiceLocator;
import localhost.ormrpc.services.WSWeiXunWebService.WSWeiXunWebServiceSrvProxy;
import localhost.ormrpc.services.WSWeiXunWebService.WSWeiXunWebServiceSrvProxyServiceLocator;
import org.json.JSONException;
import org.json.JSONObject;
import org.restlet.data.Form;
import org.restlet.ext.json.JsonRepresentation;
import com.hhxh.weixun.utils.PropertiesUtil;
import client.WSContext;
/**
* Copyright (C), 2015-2025 Hhxh Tech. Co., Ltd
*
* 动态模块接口实现
*
* @author dhy
*
* date: 2015-01-29
*/
public class WeiXunEasServiceHelper{
protected final static DateFormat DF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
protected final static DateFormat DF1 = new SimpleDateFormat("yyyy-MM-dd");
/**
* 登陆eas
* @param form
* @return
* @throws JSONException
* @throws SQLException
*/
public static JsonRepresentation easLogin(Form form) throws JSONException, SQLException {
JSONObject jsonObject = new JSONObject();
jsonObject.put("sessionid", "");
String userName = dealNull(form.getFirstValue("userName"));
String password = dealNull(form.getFirstValue("password"));
EASLoginProxyServiceLocator loginLocator = new EASLoginProxyServiceLocator();
try {
EASLoginProxy loginProxy = loginLocator.getEASLogin();
System.out.println("------ 开始登录服务器 .... ");
WSContext context = loginProxy.login(userName, password, PropertiesUtil.slnName, PropertiesUtil.dcName, PropertiesUtil.language, PropertiesUtil.dbType);
String sessionId = context.getSessionId();
if(sessionId!=null)
{
System.out.println("------ 登陆成功,SessionID:" + sessionId);
jsonObject.put("sessionid", sessionId);
}
} catch (ServiceException | RemoteException e) {
e.printStackTrace();
}
return new JsonRepresentation(jsonObject);
}
/**
* 退出eas
* @param form
* @return
* @throws JSONException
* @throws SQLException
*/
public static JsonRepresentation easLoginOut(Form form) throws JSONException, SQLException {
JSONObject jsonObject = new JSONObject();
String userName = dealNull(form.getFirstValue("userName"));
EASLoginProxyServiceLocator loginSrv = new EASLoginProxyServiceLocator();
boolean out = false;
try {
EASLoginProxy loginClient = loginSrv.getEASLogin();
out = loginClient.logout(userName, PropertiesUtil.slnName, PropertiesUtil.dcName, PropertiesUtil.language);
} catch (RemoteException | ServiceException e) {
e.printStackTrace();
}
jsonObject.put("status", out==true?"1":"0");
jsonObject.put("message", out==true?"退出成功":"退出失败");
return new JsonRepresentation(jsonObject);
}
/**
* 调用eas webservice接口方法
* @param form
* @return
* @throws JSONException
* @throws SQLException
*/
public static JsonRepresentation invoke(Form form) throws JSONException, SQLException {
String operateType = form.getFirstValue("operateType");
if(operateType==null || operateType.trim().length()==0)
{
return new JsonRepresentation(retMsg("0","参数operateType不能为空"));
}
String sessionId = form.getFirstValue("sessionId");
if(sessionId==null || sessionId.trim().length()==0)
{
return new JsonRepresentation(retMsg("0","参数sessionId不能为空"));
}
String param = form.getFirstValue("param");
if(param==null)
{
return new JsonRepresentation(retMsg("0","参数param不能为空"));
}
WSWeiXunWebServiceSrvProxyServiceLocator bsdLocator = new WSWeiXunWebServiceSrvProxyServiceLocator();
String retValues = null;
try {
WSWeiXunWebServiceSrvProxy proxy = bsdLocator.getWSWeiXunWebService();
System.out.println(sessionId);
Class clazz = proxy.getClass();
Method method = clazz.getDeclaredMethod(operateType, String.class, String.class);
retValues = (String)method.invoke(proxy,sessionId, param);
} catch (NoSuchMethodException e) {
e.printStackTrace();
return new JsonRepresentation(retMsg("0","接口调用失败,参数operateType错误"));
} catch (ServiceException e) {
e.printStackTrace();
return new JsonRepresentation(retMsg("0","接口调用失败"));
} catch (IllegalAccessException e) {
e.printStackTrace();
return new JsonRepresentation(retMsg("0","接口调用失败,请确认是否已登陆"));
} catch (IllegalArgumentException e) {
e.printStackTrace();
return new JsonRepresentation(retMsg("0","接口调用失败,请确认是否已登陆"));
} catch (InvocationTargetException e) {
e.printStackTrace();
return new JsonRepresentation(retMsg("0","接口调用失败,请确认是否已登陆"));
}
return new JsonRepresentation(retValues);
}
private static JSONObject retMsg(String status,String message)
{
JSONObject reJson = new JSONObject();
try
{
reJson.put("status", status);
reJson.put("message", message);
}
catch (JSONException e1)
{
e1.printStackTrace();
}
return reJson;
}
private static String dealNull(String arg)
{
if(arg==null || arg.trim().length()==0 || "null".equalsIgnoreCase(arg))
{
return "";
}else
{
return arg.toString();
}
}
}
本文详细介绍了如何通过企业级WebService接口进行操作,包括登陆EAS服务器、退出、以及调用接口方法等核心流程,并提供了代码实现示例。

647

被折叠的 条评论
为什么被折叠?



