金蝶EAS WebService开启安全性后,调用方法代码
- 首先登录获取 SessionID
public static String login() throws ServiceException, RemoteException {
EASLoginProxyServiceLocator locator = new EASLoginProxyServiceLocator();
EASLoginProxy login = locator.getEASLogin();
WSContext context = login.login("xxx", "xxx", "eas", "xxx", "L2", 1);
return context.getSessionId();
}
- 调用方法前,先获取SessionID
String sessionID = login();
- 调用具体方面前,设置head头信息
((Stub) proxy).setHeader("http://login.webservice.bos.kingdee.com", "SessionId", sessionID);
- 整合起来如下:
public static void testMaterial() throws RemoteException, ServiceException {
String sessionID = login();
WSMaterialWSFacadeSrvProxyService service = new WSMaterialWSFacadeSrvProxyServiceLocator();
try {
WSMaterialWSFacadeSrvProxy proxy= service.getWSMaterialWSFacade();
((Stub) proxy).setHeader("http://login.webservice.bos.kingdee.com", "SessionId", sessionID);
System.out.println("materialInfo:" + wsFacade.getMaterialInfo());
} catch (RemoteException | ServiceException e) {
e.printStackTrace();
}
}
- 引入的类/包名
import com.kingdee.eas.xxx.login.webservice.EASLoginProxy;
import com.kingdee.eas.xxx.login.webservice.EASLoginProxyServiceLocator;
import com.kingdee.eas.xxx.login.webservice.WSContext;
import com.kingdee.eas.xxx.material.webservice.WSMaterialWSFacadeSrvProxy;
import com.kingdee.eas.xxx.material.webservice.WSMaterialWSFacadeSrvProxyService;
import com.kingdee.eas.xxx.material.webservice.WSMaterialWSFacadeSrvProxyServiceLocator;
import org.apache.axis.client.Stub;
- 需要的jar包
![在这里插入图片描述](https://img-blog.csdnimg.cn/2020072311542617.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzMDIzNzU0,size_16,color_FFFFFF,t_70)
- POM依赖
<dependencies>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>net.sf.ezmorph</groupId>
<artifactId>ezmorph</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>