using Sinvo.EplanHpD.Plugin.DynaClient.CADIService; using Sinvo.EplanHpD.Plugin.DynaClient.Model; using System; using System.Collections.Generic; using System.Linq; using System.ServiceModel; using System.Text; using System.Threading.Tasks; namespace Sinvo.EplanHpD.Plugin.DynaClient { public class DynaServerClient { private static DynaServerClient _inst; public static DynaServerClient GetClient() { if(_inst == null) { _inst = new DynaServerClient(); } return _inst; } private CADIServicePortTypeClient _client; private DynaServerClient( ) { InitClient(); } public DynaServerClient(string serverUrl) { InitClient(serverUrl); } private void InitClient(string serverUrl = "http://192.168.1.205:38080/axis2/services/CADIService?wsdl") { var binding = new BasicHttpBinding(); var endpoint = new EndpointAddress(serverUrl); // 启用Cookie管理 binding.AllowCookies = true; _client = new CADIServicePortTypeClient(binding, endpoint); } public User Login(string userName,string password,string role,string group,string clientType) { var hostName = Environment.MachineName; var xml = _client.login(userName, group, role, password, hostName, clientType); return XmlFormatStream.ConvertXMLToObjectList(xml)?.FirstOrDefault(); } public List GetUserGroup(string userName) { var groupFieldName = "GUID|ID|NAME|LIBRARYGUID"; var xml = _client.listGroupByUser(userName, groupFieldName); return XmlFormatStream.ConvertXMLToObjectList(xml); } public List GetUserRole(string userName,string groupId) { string roleFieldName = "ID|NAME"; var xml = _client.listRoleByUserInGroup(userName, groupId, roleFieldName); return XmlFormatStream.ConvertXMLToObjectList(xml); } public void LoginOut() { _client.logout(); } public bool IsLoginExpired() { var xml = _client.isSessionExpired(); try { XmlFormatStream.CheckXmlException(xml); return true; } catch (System.Exception) { return false; } } } }