public bool Login(User objUser)
        {
            //configCompany = Conn.Company;
            bool isValidUser = false;
            EndpointBindingType bindingType = EndpointBindingType.BasicHttp;
            string epicorUserID             = objUser.UserId;   //Conn.epicorUserID;
            string epiorUserPassword        = objUser.Password; //Conn.epiorUserPassword;
            Guid   sessionId = Guid.Empty;

            svcSession.SessionModSvcContractClient sessionModClient = null;

            string scheme = "https";

            if (bindingType == EndpointBindingType.SOAPHttp)
            {
                scheme = "http";
            }
            UriBuilder builder = new UriBuilder(scheme, Conn.hostName);

            builder.Path = $"{Conn.environment}/Ice/Lib/SessionMod.svc";

            try
            {
                sessionModClient = GetClient <svcSession.SessionModSvcContractClient, svcSession.SessionModSvcContract>
                                   (
                    builder.Uri.ToString(),
                    epicorUserID,
                    epiorUserPassword,
                    bindingType
                                   );

                string siteID = "", siteName = "", workstationID = "", workstationDesc = "";
                string employeeID = "", countryGroupCode = "", countryCode = "", tenantID = "";

                sessionId = sessionModClient.Login();

                builder.Path     = $"{Conn.environment}/Ice/Lib/SessionMod.svc";
                sessionModClient = GetClient <svcSession.SessionModSvcContractClient, svcSession.SessionModSvcContract>(builder.Uri.ToString(), epicorUserID, epiorUserPassword, bindingType);

                sessionModClient.Endpoint.EndpointBehaviors.Add(new HookServiceBehavior(sessionId, epicorUserID));

                //** CHANGE configCompany & configPlant to read from input **//
                sessionModClient.SetCompany(string.IsNullOrEmpty(objUser.Company) ? Conn.Company : objUser.Company, out siteID, out siteName, out workstationID,
                                            out workstationDesc, out employeeID, out countryGroupCode,
                                            out countryCode, out tenantID);
                sessionModClient.SetPlant(string.IsNullOrEmpty(objUser.Plant) ?Conn.Plant: objUser.Plant);


                if (sessionId != Guid.Empty)
                {
                    isValidUser = true;
                }


                return(isValidUser);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    throw new Exception($"Epicor Error : {ex.InnerException.Message.ToString()}");
                }
                else
                {
                    throw new Exception($"Epicor Error : {ex.Message.ToString()}");
                }
            }
            finally
            {
                if (sessionId != Guid.Empty)
                {
                    sessionModClient.Logout();
                }
            }
        }
Ejemplo n.º 2
0
        public EpiResponse Process(SOHd objSOHd)
        {
            EndpointBindingType bindingType = EndpointBindingType.BasicHttp;
            string epicorUserID             = Config.epicorUserID;      //"manager";
            string epiorUserPassword        = Config.epiorUserPassword; //"finlucky08";
            Guid   sessionId = Guid.Empty;

            svcSession.SessionModSvcContractClient sessionModClient = null;

            string scheme = "https";

            if (bindingType == EndpointBindingType.SOAPHttp)
            {
                scheme = "http";
            }
            UriBuilder builder = new UriBuilder(scheme, Config.hostName);

            builder.Path = $"{Config.environment}/Ice/Lib/SessionMod.svc";

            EpiResponse objEpiRes = null;

            try
            {
                sessionModClient = GetClient <svcSession.SessionModSvcContractClient, svcSession.SessionModSvcContract>
                                   (
                    builder.Uri.ToString(),
                    epicorUserID,
                    epiorUserPassword,
                    bindingType
                                   );



                sessionId = sessionModClient.Login();

                builder.Path     = $"{Config.environment}/Ice/Lib/SessionMod.svc";
                sessionModClient = GetClient <svcSession.SessionModSvcContractClient, svcSession.SessionModSvcContract>(builder.Uri.ToString(), epicorUserID, epiorUserPassword, bindingType);

                sessionModClient.Endpoint.EndpointBehaviors.Add(new HookServiceBehavior(sessionId, epicorUserID));



                string newCompany             = string.Empty;
                string plant                  = string.Empty;
                string siteID                 = string.Empty;
                string siteName               = string.Empty;
                string workstationID          = string.Empty;
                string workstationDescription = string.Empty;
                string employeeID             = string.Empty;
                string countryGroupCode       = string.Empty;
                string countryCode            = string.Empty;
                string tenantID               = string.Empty;


                sessionModClient.SetCompany(objSOHd.Company, out siteID, out siteName, out workstationID, out workstationDescription, out employeeID, out countryGroupCode, out countryCode, out tenantID);
                sessionModClient.SetPlant(Config.Plant);

                if (sessionId != Guid.Empty)
                {
                    //Call the Require function
                    objEpiRes = SOUpdate(epicorUserID, epiorUserPassword, builder, sessionId, objSOHd);
                }
                else
                {
                    throw new Exception($"Error : Sessionid is Empty!");
                }
            }
            catch (Exception ex)
            {
                objEpiRes        = new EpiResponse();
                objEpiRes.ErrMsg = $"Epicor (SalesOrderEntry) Error : {ex.Message.ToString()}";
            }
            finally
            {
                if (sessionId != Guid.Empty)
                {
                    sessionModClient.Logout();
                }
            }
            return(objEpiRes);
        }