public void NextJob(NbtAuth auth, PrinterSetupData aprinter)
        {
            NbtPublicClient NbtClient = _getClient(auth);

            NextJobEventArgs e = new NextJobEventArgs();

            e.printer.PrinterKey  = aprinter.PrinterKey;
            e.printer.PrinterName = aprinter.PrinterName;
            e.printer.LPCname     = aprinter.LPCname;
            e.auth.AccessId       = auth.AccessId;
            e.auth.UserId         = auth.UserId;
            e.auth.Password       = auth.Password;
            e.auth.baseURL        = auth.baseURL;
            e.auth.useSSL         = auth.useSSL;

            CswNbtLabelJobRequest labelReq = new CswNbtLabelJobRequest();

            labelReq.PrinterKey = e.printer.PrinterKey;

            CswNbtLabelJobResponse Ret;

            using (OperationContextScope Scope = new OperationContextScope(NbtClient.InnerChannel))
            {
                WebOperationContext.Current.OutgoingRequest.Headers.Add("X-NBT-SessionId", auth.sessionId);
                Ret = NbtClient.LpcGetNextJob(labelReq);
            }

            if (Ret.Authentication.AuthenticationStatus == "NonExistentSession")
            {
                //the old session has timed out, and we need to authenticate again
                CswNbtWebServiceSessionCswNbtAuthReturn authAttempt = _Authenticate(auth, e, NbtClient);
                if (authAttempt.Authentication.AuthenticationStatus == "Authenticated")
                {
                    NextJob(auth, aprinter);
                }
            }
            else if (Ret.Authentication.AuthenticationStatus == "Authenticated")
            {
                if (Ret.Status.Success)
                {
                    e.Succeeded      = true;
                    e.Job            = Ret;
                    aprinter.LPCname = Ret.PrinterName;
                }
                else
                {
                    e.Message = "Error calling NextLabelJob web service. ";
                    if (Ret.Status.Errors.Length > 0)
                    {
                        e.Message += Ret.Status.Errors[0].Message;
                    }
                }


                if (OnNextJob != null)
                {
                    OnNextJob(e);
                }
            }
        }//NextJob()
        public void LabelById(NbtAuth auth, string labelid, string targetid, PrinterSetupData aprinter)
        {
            NbtPublicClient NbtClient = _getClient(auth);

            LabelByIdEventArgs e = new LabelByIdEventArgs();

            e.printer.PrinterName = aprinter.PrinterName;

            NbtPrintLabelRequestGet nbtLabelget = new NbtPrintLabelRequestGet();

            nbtLabelget.LabelId  = labelid;
            nbtLabelget.TargetId = targetid;

            CswNbtLabelEpl Ret;

            using (OperationContextScope Scope = new OperationContextScope(NbtClient.InnerChannel))
            {
                WebOperationContext.Current.OutgoingRequest.Headers.Add("X-NBT-SessionId", auth.sessionId);
                Ret = NbtClient.LpcGetLabel(nbtLabelget);
            }

            if (Ret.Authentication.AuthenticationStatus == "NonExistentSession")
            {
                //the old session has timed out, and we need to authenticate again
                CswNbtWebServiceSessionCswNbtAuthReturn authAttempt = _Authenticate(auth, e, NbtClient);
                if (authAttempt.Authentication.AuthenticationStatus == "Authenticated")
                {
                    LabelById(auth, labelid, targetid, aprinter);
                }
            }
            else if (Ret.Authentication.AuthenticationStatus == "Authenticated")
            {
                if (Ret.Status.Success)
                {
                    if (Ret.Data.Labels.Length < 1)
                    {
                        e.Message = "No labels returned.";
                    }
                    else
                    {
                        e.Succeeded = true;
                        foreach (PrintLabel p in Ret.Data.Labels)
                        {
                            e.LabelData += p.EplText + "\r\n";
                        }
                    }
                }
                else
                {
                    e.Message += Ret.Status.Errors[0].Message;
                }
                if (OnLabelById != null)
                {
                    OnLabelById(e);
                }
            }
        } // LabelById()
        public void Register(NbtAuth auth, PrinterSetupData aprinter)
        {
            RegisterEventArgs e = new RegisterEventArgs();

            try
            {
                NbtPublicClient NbtClient = _getClient(auth);
                LabelPrinter    lblPrn    = new LabelPrinter();
                lblPrn.LpcName     = aprinter.LPCname;
                lblPrn.Description = aprinter.Description;

                CswNbtLabelPrinterReg Ret;
                using (OperationContextScope Scope = new OperationContextScope(NbtClient.InnerChannel))
                {
                    WebOperationContext.Current.OutgoingRequest.Headers.Add("X-NBT-SessionId", auth.sessionId);
                    Ret = NbtClient.LpcRegister(lblPrn);
                }
                if (Ret.Authentication.AuthenticationStatus == "NonExistentSession")
                {
                    //the old session has timed out, and we need to authenticate again
                    CswNbtWebServiceSessionCswNbtAuthReturn authAttempt = _Authenticate(auth, e, NbtClient);
                    if (authAttempt.Authentication.AuthenticationStatus == "Authenticated")
                    {
                        Register(auth, aprinter);
                    }
                }//if previous authentication timed out
                else if (Ret.Authentication.AuthenticationStatus == "Authenticated")
                {
                    if (Ret.Status.Success)
                    {
                        e.printer.PrinterKey = Ret.PrinterKey;
                        e.printer.Message    = "Registered PrinterKey=" + e.printer.PrinterKey;
                        e.printer.Succeeded  = true;
                    }
                    else
                    {
                        e.printer.Message    = "Printer \"" + aprinter.LPCname + "\" registration failed. ";
                        e.printer.PrinterKey = string.Empty;
                        if (Ret.Status.Errors.Length > 0)
                        {
                            e.printer.Message += Ret.Status.Errors[0].Message;
                        }
                    }


                    if (OnRegisterLpc != null)
                    {
                        OnRegisterLpc(e);
                    }
                } //else when authentication was successful
            }     //try
            catch (Exception Error)
            {
                e.Message         = "Printer registration failed. Please check server settings.";
                e.printer.Message = "Printer registration failed. Please check server settings.";
            }
        } // Register()