Webservice EASLogin登录接口说明及安全模式

新手入门建议先看这篇文章:EAS Cloud WebService开发最佳实践
安全模式
安全模式是EAS-WebService开发特有的概念,即webservice实际调用业务接口的时候需要传递用户会话信息(SessionId)验证登陆权限之后,才可以调用业务逻辑。
问题表现
当不使用安全模式调用WebService接口,会出现以下异常问题:
1) 程序报错:com.kingdee.bos.webservice.WSInvokeException ; com.kingdee.bos.orm.rmi.RMIException
2) 程序报错,会话异常,让重新登录:please login first
3) 程序报错,会话找不到:session not found
4) 数据异常,串用户
问题原因
出现上述异常的原因是:
1) 在使用 单独的EAS实例端口 调用 的时候,未在接口报文中传递登录接口所返回的用户会话(SessionId)
2) 在使用 EAS集群端口 调用 的时候,未在接口报文中传递登录接口所返回的用户会话(SessionId)以及登录接口所返回的cookie
正确的EAS-WebService调用图解(即使用安全模式)如下:
1) 单独的EAS实例端口 调用

2) 使用 EAS集群端口 调用

解决方案
请确认调用方用的端口是 eas的具体实例端口 还是 群集端口,两种端口修改方案如下
实例端口调用
注意:85版本以后实例端口不能是实例1
启用安全模式
1. 修改eas\Server\eas\server\profiles\server*\config\webservice.propeties文件,另起一行,添加参数如下:(注意参数名和值不要写错)
2. isRomoteLocate=false
3. 重启服务
java调用
配置文件修改后webservice调用端需要把登录返回的SessionId传过去,java调用示例如下
EASLoginProxy proxy =null;
WSContext context = null;
//登录
proxy = new EASLoginProxyServiceLocator().getEASLogin();
context= proxy.login("kdjgf", "", "eas", "zs70sp5", "l2", 1);
if(context. getSessionId() == null ){throw new Exception(“login fail”);}
//具体业务调用
String[][] vouchers= null;
WSGLWebServiceFacadeSrvProxy proxyWS= null;
proxyWS = new WSGLWebServiceFacadeSrvProxyServiceLocator().getWSGLWebServiceFacade();
//在soap-xml的header中设置登录返回的SessionId。Key是 "http://login.webservice.bos.kingdee.com"是固定的
((Stub) proxyWS).setHeader("http://login.webservice.bos.kingdee.com","SessionId", context.getSessionId());
vouchers = proxyWS.getVoucher("001", "2008", "5", 0, 0);其本质是,每次webservice访问的报文xml,必须带上登录接口返回的SessionId 信息,如下<soapenv:Header>部分。系统将根据 <soapenv:Header>的SessionId 信息,获取相关的上下文信息。
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservice.app.message.base.eas.kingdee.com"> <soapenv:Header> <ns1:SessionId xmlns:ns1="http://login.webservice.bos.kingdee.com"> 2be84d9e-ed91-4fa5-a8e5-f39440e41ed2 </ns1:SessionId> </soapenv:Header> <soapenv:Body> <web:getBillUrl soapen> <assignId xsi:type="xsd:string"></assignId> <procinstId xsi:type="xsd:string"></procinstId> </web:getBillUrl> </soapenv:Body> </soapenv:Envelope>
集群端口调用
启用安全模式
1. 修改eas\Server\eas\server\profiles\server*\config\webservice.propetties文件,另起一行,添加参数如下:(注意参数名和值不要写错)
2. isRomoteLocate=false
server/deploy/eas.ear/web.war/WEB-INF/server-config.wsdd文件中添加全局参数,保证服务端返回设置的cookie:
<parameter name="scope" value="session"/>

java调用
相对实例端口调用的java代码,额外增加如下 关键代码:
//获取登录之后的cookie,然后再对业务请求设置cookie loginStub._getCall().getMessageContext().getProperty(HTTPConstants.HEADER_COOKIE); proxyWSStub._setProperty(HTTPConstants.HEADER_COOKIE, (String[])cookie); //保证请求的时候会携带cookie loginStub.setMaintainSession(true); proxyWSStub.setMaintainSession(true);
完整样例:
import org.apache.axis.client.Stub;
import org.apache.axis.transport.http.HTTPConstants;
EASLoginProxy loginProxy =null;
WSContext context = null;
//登录
loginProxy = new EASLoginProxyServiceLocator().getEASLogin();
Stub loginStub = (Stub) loginProxy;
loginStub.setMaintainSession(true);
context= loginProxy.login("kdjgf", "", "eas", "zs70sp5", "l2", 1);
if(context. getSessionId() == null ){throw new Exception(“login fail”);}
//具体业务调用代码
String[][] vouchers= Webservice EASLogin登录接口说明及安全模式
声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。



