private void CreateRemoteServiceBinding()
        {
            if (!this.ServiceBroker.RemoteServiceBindings.Contains(this.BindingFullName))
            {
                RemoteServiceBinding bind =
                    new RemoteServiceBinding(this.ServiceBroker, this.BindingFullName);
                bind.IsAnonymous     = this.AllowAnonymous;
                bind.CertificateUser = this.ServiceOwnerName;
                bind.Owner           = this.ServiceOwnerName;
                bind.RemoteService   = this.FullName;

                bind.Create();
            }
        }
        public BrokerServiceConfiguration(string fullName, ServiceBroker serviceBroker)
            : base(serviceBroker)
        {
            if (this.ServiceBroker.Services.Contains(fullName))
            {
                BrokerService item = this.ServiceBroker.Services[fullName];

                base.Urn = new Uri(base.Urn.ToString() + "service/");

                m_Name = item.Name.Substring
                             (base.Urn.ToString().Length, item.Name.Length - base.Urn.ToString().Length);

                m_QueueName           = item.QueueName;
                this.ServiceOwnerName = item.Owner;

                //Fill ContractNames from ServiceContractMapping
                foreach (ServiceContractMapping map in item.ServiceContractMappings)
                {
                    m_ContractNames.Add(map.Name);
                }

                //CertificateConfiguration for this Service
                //CertificateName is store in ExtendedProperties to match the Service to the Certificate
                if (item.ExtendedProperties.Contains("CertificateName"))
                {
                    CertificateConfiguration cert = new
                                                    CertificateConfiguration(item.ExtendedProperties["CertificateName"].Value.ToString(),
                                                                             this.ServiceBroker);
                    this.Certificate = cert;
                }

                //RemoteServiceBinding for this Service if it exists
                string bindingFullName = base.BaseUrn + "RemoteServiceBinding/" + this.Name + "Binding";
                if (this.ServiceBroker.RemoteServiceBindings.Contains(bindingFullName))
                {
                    this.EnableRemoteService = true;
                    RemoteServiceBinding binding = this.ServiceBroker.
                                                   RemoteServiceBindings[bindingFullName];

                    this.RemoteServiceBinding.CertificateUser = binding.CertificateUser;
                    this.RemoteServiceBinding.IsAnonymous     = binding.IsAnonymous;
                    this.AllowAnonymous                     = binding.IsAnonymous;
                    this.RemoteServiceBinding.Name          = binding.Name;
                    this.RemoteServiceBinding.Owner         = binding.Owner;
                    this.RemoteServiceBinding.RemoteService = binding.RemoteService;
                }
            }
        }
        public RemoteServiceBindingConfiguration(string fullName, ServiceBroker serviceBroker)
            : base(serviceBroker)
        {
            if (this.ServiceBroker.RemoteServiceBindings.Contains(fullName))
            {
                RemoteServiceBinding item = this.ServiceBroker.RemoteServiceBindings[fullName];

                base.Urn = new Uri(base.Urn.ToString() + "RemoteServiceBinding/");

                m_Name = item.Name.Substring
                             (base.Urn.ToString().Length, item.Name.Length - base.Urn.ToString().Length);

                m_Owner           = item.Owner;
                m_CertificateUser = item.CertificateUser;
                m_RemoteService   = item.RemoteService;
                m_IsAnonymous     = item.IsAnonymous;
            }
        }
        public void Drop()
        {
            if (this.ServiceBroker.Services.Contains(this.FullName))
            {
                this.ServiceBroker.Services[this.FullName].Drop();

                if (this.ServiceBroker.RemoteServiceBindings.Contains(this.BindingFullName))
                {
                    RemoteServiceBinding binding = this.ServiceBroker.
                                                   RemoteServiceBindings[this.BindingFullName];
                    binding.Drop();
                }
            }

            //Drop Certificate
            if (m_EnableRemoteServiceBinding && !this.AllowAnonymous)
            {
                this.DropCertificate();
            }
        }
        public void Alter()
        {
            BrokerService    brokerService;
            ExtendedProperty prop = null;

            if (this.ServiceBroker.Services.Contains(this.FullName))
            {
                brokerService = this.ServiceBroker.Services[this.FullName];

                brokerService.QueueName = this.QueueName;

                //Drop Contracts that user removed
                foreach (ServiceContractMapping map in brokerService.ServiceContractMappings)
                {
                    if (!this.ContractNames.Contains(map.Name))
                    {
                        if (map.State != SqlSmoState.ToBeDropped)
                        {
                            map.MarkForDrop(true);
                        }
                    }
                }
                //Add Contracts that user added
                foreach (string name in this.ContractNames)
                {
                    if (!brokerService.ServiceContractMappings.Contains(name))
                    {
                        ServiceContractMapping brokerServiceContract
                            = new ServiceContractMapping(brokerService, name);
                        brokerService.ServiceContractMappings.Add(brokerServiceContract);
                    }
                }

                brokerService.Alter();

                //Drop RemoteServiceBinding and Certificate
                if (!m_EnableRemoteServiceBinding)
                {
                    if (this.ServiceBroker.RemoteServiceBindings.Contains(this.BindingFullName))
                    {
                        RemoteServiceBinding binding = this.ServiceBroker.
                                                       RemoteServiceBindings[this.BindingFullName];
                        binding.Drop();
                    }

                    this.DropCertificate();
                    //Drop extended property
                    if (brokerService.ExtendedProperties.Contains("CertificateName"))
                    {
                        brokerService.ExtendedProperties["CertificateName"].Drop();
                    }
                }

                //Change RemoteServiceBinding
                if (m_EnableRemoteServiceBinding && !String.IsNullOrEmpty(this.ServiceOwnerName))
                {
                    if (this.ServiceBroker.RemoteServiceBindings.Contains(this.BindingFullName))
                    {
                        RemoteServiceBinding binding = this.ServiceBroker.
                                                       RemoteServiceBindings[this.BindingFullName];
                        binding.IsAnonymous = this.AllowAnonymous;
                        //Can't change service owner binding.Owner = this.ServiceOwnerName;

                        binding.Alter();
                    }
                }

                //Create Certificate if EnableRemoteServiceBinding = true and AllowAnonymous = false
                if (m_EnableRemoteServiceBinding &&
                    !String.IsNullOrEmpty(this.ServiceOwnerName) && !this.AllowAnonymous)
                {
                    if (!brokerService.ExtendedProperties.Contains("CertificateName"))
                    {
                        prop = new ExtendedProperty(brokerService,
                                                    "CertificateName", this.Certificate.Name);
                    }

                    this.Certificate.Owner = this.ServiceOwnerName;
                    this.Certificate.Create();
                }

                //Create ReportServiceBinding
                if (m_EnableRemoteServiceBinding && !String.IsNullOrEmpty(this.ServiceOwnerName))
                {
                    this.CreateRemoteServiceBinding();
                }

                if (this.GrantReceive)
                {
                    CreateGrantReceive();
                }

                //Create property last
                if (prop != null)
                {
                    prop.Create();
                }
            }
        }
        private void CreateRemoteServiceBinding()
        {
            if (!this.ServiceBroker.RemoteServiceBindings.Contains(this.BindingFullName))
            {
                RemoteServiceBinding bind =
                    new RemoteServiceBinding(this.ServiceBroker, this.BindingFullName);
                bind.IsAnonymous = this.AllowAnonymous;
                bind.CertificateUser = this.ServiceOwnerName;
                bind.Owner = this.ServiceOwnerName;
                bind.RemoteService = this.FullName;

                bind.Create();
            }
        }
Beispiel #7
0
        int UpDateSsb()
        {
            updatedobj = null;
              //if (!isDirty)
            //return 0;
              if (!ValidateData()) {
            Cursor crs = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;

            try {
              Database db = null;

              ServiceBroker sb = null;
              if (ssbType != SsbEnum.Database && ssbType != SsbEnum.Login && ssbType != SsbEnum.EndPoint) {
             sb = dBase.ServiceBroker;
              }
              switch (ssbType) {
            case SsbEnum.Database:
              MasterKey mk = null;
              SSBIDatabase sbd = null;
              if (isEdit) {
                sbd = (SSBIDatabase)objToUpdate;
                db = sbd.DataBase;
              }
              else {
                db = new Database();
                db.Name = txtName.Text;
                db.Parent = dbServ.SMOServer;
              }

              if (isEdit) {
               if(db.MasterKey != null && db_chkMasterKey.Checked == false) {
                 mk = db.MasterKey;
                 mk.Drop();

               }
               else if (db.MasterKey == null && db_chkMasterKey.Checked) {
                 mk = new MasterKey();
                 mk.Parent = db;
                 mk.Create(db_txtMkPwd.Text);
               }

               db.Alter();
               if (sbd.IsTrustworthy != db_chkTrustWorthy.Checked)
                 sbd.IsTrustworthy = db_chkTrustWorthy.Checked;

              }
              else {
                db.Create();
                sbd = new SSBIDatabase(db);

                if (db_chkMasterKey.Checked) {
                  mk = new MasterKey();
                  mk.Parent = db;
                  mk.Create(db_txtMkPwd.Text);

                }

                if (db_chkTrustWorthy.Checked) {
                  sbd.IsTrustworthy = true;
                }

              }
              if (dBase == null)
                dBase = db;

              //Server serv = db.Parent;

              updatedobj = db;
              break;
            case SsbEnum.MessageType:
              MessageType mt = null;
              if (isEdit)
                mt = (MessageType)objToUpdate;
              else {
                mt = new MessageType();
                mt.Parent = sb;
                mt.Name = txtName.Text;
              }
              if (cboUser.Text != string.Empty)
                mt.Owner = cboUser.Text;
              mt.MessageTypeValidation = (MessageTypeValidation)Enum.Parse(typeof(MessageTypeValidation), cboVal.Text);
              if (cboValSchema.Enabled)
                mt.ValidationXmlSchemaCollection = cboValSchema.Text;

              if (isEdit)
                mt.Alter();
              else
                mt.Create();
              updatedobj = mt;
              break;

            case SsbEnum.Contract:
              ServiceContract sc = new ServiceContract();
              sc.Parent = sb;
              sc.Name = txtName.Text;
              if (cboUser.Text != string.Empty)
                sc.Owner = cboUser.Text;
              //get the message types
              foreach (DataGridViewRow row in dvMsgTypes.Rows) {
                sc.MessageTypeMappings.Add(new MessageTypeMapping(sc, row.Cells[0].Value.ToString(), (MessageSource)Enum.Parse(typeof(MessageSource), row.Cells[1].Value.ToString())));
              }

              if (isEdit)
                sc.Alter();
              else
                sc.Create();

              updatedobj = sc;
              break;

            case SsbEnum.Queu:
              ServiceQueue q = null;
              if (isEdit)
                q = (ServiceQueue)objToUpdate;
              else {
                q = new ServiceQueue();
                q.Parent = sb;
                q.Name = txtName.Text;
              }
              q.IsEnqueueEnabled = chkStatus.Checked;
              if (chkRetention.Checked)
                q.IsRetentionEnabled = true;

              //if (chkActivation.Checked) {
              //if(isEdit)
              //  q.IsActivationEnabled = chkActivation.Checked;
              //
              if (chkActivation.Checked) {
                q.IsActivationEnabled = chkActivation.Checked;
                if (dBase.Name != cboQDb.Text)
                  q.ProcedureDatabase = cboQDb.Text;
                StoredProcedure sp = (StoredProcedure)cboProc.SelectedItem;
                q.ProcedureSchema = sp.Schema;
                q.ProcedureName = cboProc.Text;
                q.MaxReaders = short.Parse(txtReaders.Text);
                if (rdOwner.Checked)
                  q.ActivationExecutionContext = ActivationExecutionContext.Owner;
                else if (rdSelf.Checked)
                  q.ActivationExecutionContext = ActivationExecutionContext.Self;
                else if (rdUser.Checked) {
                  q.ActivationExecutionContext = ActivationExecutionContext.ExecuteAsUser;
                  q.ExecutionContextPrincipal = txtExecuteAs.Text;
                }

              }

              if (isEdit)
                q.Alter();
              else
                q.Create();

              updatedobj = q;

              break;

            case SsbEnum.Service:
              BrokerService bserv = null;
              if (isEdit)
                bserv = (BrokerService)objToUpdate;
              else {
                bserv = new BrokerService();
                bserv.Parent = sb;
                bserv.Name = txtName.Text;
              }
              if (cboUser.Text != string.Empty)
                bserv.Owner = cboUser.Text;

              ServiceQueue servq = (ServiceQueue)cboQueue.SelectedItem;
              bserv.QueueName = servq.Name;
              bserv.QueueSchema = servq.Schema;

              if (lbChosenCtr.Items.Count > 0) {
                foreach (object o in lbChosenCtr.Items) {
                  ServiceContract servctr = o as ServiceContract;
                  ServiceContractMapping scm = new ServiceContractMapping(bserv, servctr.Name);
                  bserv.ServiceContractMappings.Add(scm);
                }
              }

              if (isEdit)
                bserv.Alter();
              else
                bserv.Create();

              updatedobj = bserv;

              break;

            case SsbEnum.Route:
              ServiceRoute srt = null;
              if (isEdit)
                srt = (ServiceRoute)objToUpdate;
              else {
                srt = new ServiceRoute();
                srt.Name = txtName.Text;
                srt.Parent = sb;
              }

              if (cboUser.Text != string.Empty)
                srt.Owner = cboUser.Text;

              if (textBroker.Text != string.Empty)
                srt.BrokerInstance = textBroker.Text;

              if (textRemote.Text != string.Empty)
                srt.RemoteService = textRemote.Text;

              if (textLifeTime.Text != string.Empty)
                srt.ExpirationDate = DateTime.Parse(textLifeTime.Text);

              if (rdLocal.Checked)
                srt.Address = "LOCAL";

              if (rdTransport.Checked)
                srt.Address = "TRANSPORT";

              if (rdTCP.Checked)
                srt.Address = "TCP://" + txtAddress.Text;

              if (txtMirror.Text != string.Empty)
                srt.MirrorAddress = "TCP://" + txtMirror.Text;

              //StringCollection sColl = srt.Script();
              //foreach (string s in sColl)
              //  MessageBox.Show(s);

              if (isEdit)
                srt.Alter();
              else
                srt.Create();

              updatedobj = srt;

              break;

            case SsbEnum.RemoteBinding:
              RemoteServiceBinding remBind = null;
              if (isEdit)
                remBind = (RemoteServiceBinding)objToUpdate;
              else {
                remBind = new RemoteServiceBinding();
                remBind.Name = txtName.Text;
                remBind.Parent = sb;
              }

              if (cboUser.Text != string.Empty)
                remBind.Owner = cboUser.Text;

              remBind.RemoteService = textRemServ.Text;

              remBind.CertificateUser = cboRemUser.Text;
              remBind.IsAnonymous = chkAnon.Checked;

              StringCollection sColl = remBind.Script();
              foreach (string s in sColl)
                MessageBox.Show(s);

              if (isEdit)
                remBind.Alter();
              else
                remBind.Create();

              updatedobj = remBind;

              break;

            case SsbEnum.Conversation:
              TimeSpan ts = TimeSpan.Zero;
              Guid grpHandle = Guid.Empty;
              string convContract = "DEFAULT";
              BrokerService bServ = (BrokerService)cnv_cboFrmServ.SelectedItem;

              string toService = cnv_txtToSrv.Text;

              if (cnv_txtLifetime.Text != string.Empty && cnv_txtLifetime.Text != "0")
                ts = TimeSpan.FromSeconds(double.Parse(cnv_txtLifetime.Text));

              if (cnv_cboContract.Text != string.Empty)
                convContract = cnv_cboContract.Text;

              if (cnv_txtRelGrpHndl.Text != string.Empty)
                grpHandle = new Guid(cnv_txtRelGrpHndl.Text);

              //get a service object
              Service smoserv = smo.GetSSBIService(bServ.Parent.Parent, bServ.Name);
              if (smoserv.Connection.State == ConnectionState.Closed)
                smoserv.Connection.Open();

              smoserv.Connection.ChangeDatabase(bServ.Parent.Parent.Name);
              updatedobj = smoserv.BeginDialog(toService, convContract, ts, cnv_chkEncryption.Checked, grpHandle);
              break;

            case SsbEnum.Message:
              SSBIConversation msgConv = (SSBIConversation)msg_cboConv.SelectedItem;
              string servName = msg_txtFrom.Text;
              //we need a service object
              Service msgSsbiServ = smo.GetSSBIService(dBase, msgConv.FromService);
              if (msgSsbiServ.Connection.State== ConnectionState.Closed)
                 msgSsbiServ.Connection.Open();

               msgSsbiServ.Connection.ChangeDatabase(dBase.Name);
              Conversation msgCnv = new Conversation(msgSsbiServ, msgConv.Handle);
              string msgType = msg_cboMsgType.SelectedText;
              string msgString = msg_rchMsg.Text;
              msgType = msg_cboMsgType.Text;
              MemoryStream msgBody = new MemoryStream(Encoding.ASCII.GetBytes(msgString));

              Microsoft.Samples.SqlServer.Message msg = new Microsoft.Samples.SqlServer.Message(msgType, msgBody);
              msgCnv.Send(msg);

              break;

            case SsbEnum.Login :
              string pwd = "";
              Login lg = new Login();
              lg.Parent = dbServ.SMOServer;
              lg.Name = lgn_txtLoginName.Text;
              if (lgn_rdSql.Checked) {
                pwd = lgn_txtPwd.Text;
                lg.PasswordPolicyEnforced = lgn_chkEnforcePolicy.Checked;
                lg.LoginType = LoginType.SqlLogin;
                lg.Create(pwd);
              }
              else {
                lg.Create();
              }

              updatedobj = lg;
              break;

            case SsbEnum.Certificate:
              string certOwner  = "dbo";
              int certSource = cert_cboSource.SelectedIndex;
              Certificate cert = new Certificate();
              if(!isEdit) {
                cert.Name = txtName.Text;
                if(cboUser.Text != "")
                  certOwner = cboUser.Text;
                cert.Parent = dBase;
                cert.Owner = certOwner;

              }

              cert.ActiveForServiceBrokerDialog = cert_chkBeginDlg.Checked;

              if (certSource == 0) {
                if (!isEdit) {
                  if (cert_chkMasterKey.Checked)
                    cert.Create(cert_txtCertPath.Text, CertificateSourceType.File, cert_txtPrivPath.Text, cert_txtDecrypt.Text);
                  else
                    cert.Create(cert_txtCertPath.Text, CertificateSourceType.File, cert_txtPrivPath.Text, cert_txtDecrypt.Text, cert_txtEncrypt.Text);

                }
              }
              else if (certSource == 1) {
                if (!isEdit) {
                  cert.StartDate = cert_dtValidFrom.Value;
                  cert.ExpirationDate = cert_dtExpiry.Value;
                  cert.Subject = cert_txtCertPath.Text;

                  if (cert_chkMasterKey.Checked) {
                    cert.Create();
                  }
                  else {
                    cert.Create(cert_txtEncrypt.Text);
                  }
                }

              }
              else if (certSource == 2) {
                if (!isEdit) {
                  cert.Create(cert_txtCertPath.Text, CertificateSourceType.File);
                }

              }

              if (isEdit)
                cert.Alter();

              updatedobj = cert;
              break;

            case SsbEnum.User :
              User usr;
              if (!isEdit) {
                usr = new User();
                usr.Name = txtName.Text;
                usr.Parent = dBase;
                if(usr_chkLogin.Checked)
                  usr.Login = usr_cboLogin.Text;

              }
              else
                usr = (User)objToUpdate;

              if (usr_cboCerts.SelectedIndex != -1)
                usr.Certificate = usr_cboCerts.Text;

              if (!isEdit)
                if (usr_chkLogin.Checked)
                  usr.Create();
                else
                  smo.CreateUserWithNoLogin(usr);

              else
                usr.Alter();
              updatedobj = usr;
              break;

            case SsbEnum.EndPoint :
              Endpoint ep = null;
              if (!isEdit) {
                ep = new Endpoint();
                ep.Name = txtName.Text;
                ep.Parent = dbServ.SMOServer;
                ep.ProtocolType = ProtocolType.Tcp;
                ep.EndpointType = EndpointType.ServiceBroker;
              }
              else
                ep = ((SSBIEndpoint)objToUpdate).EndPoint;

              ep.Protocol.Tcp.ListenerPort = int.Parse(ep_txtPort.Text);
              if (ep_txtIp.Text == "ALL")
                ep.Protocol.Tcp.ListenerIPAddress = System.Net.IPAddress.Any;
              else {
                ep.Protocol.Tcp.ListenerIPAddress = System.Net.IPAddress.Parse(ep_txtIp.Text);
              }
              ep.Payload.ServiceBroker.EndpointAuthenticationOrder = (EndpointAuthenticationOrder)ep_cboAuth.SelectedItem;
              if (ep_cboCert.SelectedIndex != -1)
                ep.Payload.ServiceBroker.Certificate = ep_cboCert.Text;

              ep.Payload.ServiceBroker.EndpointEncryption = (EndpointEncryption)ep_cboEncrypt.SelectedItem;
              if (ep_cboAlgorithm.SelectedIndex != -1)
                ep.Payload.ServiceBroker.EndpointEncryptionAlgorithm = (EndpointEncryptionAlgorithm)ep_cboAlgorithm.SelectedItem;

              ep.Payload.ServiceBroker.IsMessageForwardingEnabled = ep_chkFwd.Checked;

              if (ep_txtSize.Text != string.Empty)
                ep.Payload.ServiceBroker.MessageForwardingSize = int.Parse(ep_txtSize.Text);

              if(!isEdit)
                ep.Create();

              switch ((EndpointState)ep_cboState.SelectedIndex) {
                case EndpointState.Disabled :
                  ep.Disable();
                  break;

                case EndpointState.Started :
                  ep.Start();
                  break;
                case EndpointState.Stopped :
                  if (isEdit)
                    ep.Stop();
                  break;
              }

              if (isEdit)
                ep.Alter();

              break;

            case SsbEnum.CreateListing :
              CreateListing(true);

              break;

              }

              if (isEdit)
            _state = SsbState.Edited;
              else
            _state = SsbState.New;

              Cursor.Current = crs;

              this.DialogResult = DialogResult.OK;

              ExitAndClose();

            }
            catch (FailedOperationException e) {
              smo.ShowException(e);
            }
            catch (Exception ex) {
              smo.ShowException(ex);
            }

            finally {
              if(dbServ !=null)
            dbServ.SMOServer.ConnectionContext.Disconnect();

            }

              }

              return 0;
        }
Beispiel #8
0
        internal static void DeleteObject(SsbEnum sType, object smoObj)
        {
            switch (sType)
            {
            case SsbEnum.Database:
                Database db = null;
                if (smoObj.GetType() == typeof(SSBIDatabase))
                {
                    db = ((SSBIDatabase)smoObj).DataBase;
                }
                else if (smoObj.GetType() == typeof(Database))
                {
                    db = (Database)smoObj;
                }

                db.Drop();
                break;

            case SsbEnum.MessageType:
                MessageType mt = (MessageType)smoObj;
                mt.Drop();
                break;

            case SsbEnum.Contract:
                ServiceContract sc = (ServiceContract)smoObj;
                sc.Drop();
                break;

            case SsbEnum.Queu:
                ServiceQueue sq = (ServiceQueue)smoObj;
                sq.Drop();
                break;

            case SsbEnum.Service:
                BrokerService bs = (BrokerService)smoObj;
                bs.Drop();
                break;

            case SsbEnum.Route:
                ServiceRoute sr = (ServiceRoute)smoObj;
                sr.Drop();
                break;

            case SsbEnum.RemoteBinding:
                RemoteServiceBinding rsb = (RemoteServiceBinding)smoObj;
                rsb.Drop();
                break;

            case SsbEnum.Conversation:
                SSBIConversation cnv = (SSBIConversation)smoObj;
                smo.EndConversation(cnv);
                break;

            case SsbEnum.EndPoint:
                Endpoint ep = (Endpoint)smoObj;
                ep.Drop();
                break;

            case SsbEnum.Certificate:
                Certificate cert = (Certificate)smoObj;
                cert.Drop();
                break;
            }
        }
Beispiel #9
0
        internal static void DeploySsbObj(object obj, string svrName, string dbName, SsbEnum ssbType, bool isEdit)
        {
            Server               svr  = CreateServer(svrName, null, null);
            Database             db   = svr.Databases[dbName];
            ServiceBroker        sb   = db.ServiceBroker;
            MessageType          mt   = null;
            ServiceContract      sc   = null;
            ServiceQueue         q    = null;
            BrokerService        serv = null;
            ServiceRoute         rt   = null;
            RemoteServiceBinding bind = null;

            try {
                switch (ssbType)
                {
                case SsbEnum.MessageType:
                    MessageType mtNew = new MessageType();
                    mtNew.Parent = sb;
                    mt           = (MessageType)obj;
                    mtNew.Name   = mt.Name;
                    mtNew.MessageTypeValidation = mt.MessageTypeValidation;
                    if (mt.MessageTypeValidation == MessageTypeValidation.XmlSchemaCollection)
                    {
                        mtNew.ValidationXmlSchemaCollection = mt.ValidationXmlSchemaCollection;
                    }

                    if (isEdit)
                    {
                        mtNew.Alter();
                    }
                    else
                    {
                        mtNew.Create();
                    }

                    break;

                case SsbEnum.Contract:
                    ServiceContract scNew = new ServiceContract();
                    sc           = (ServiceContract)obj;
                    scNew.Parent = sb;
                    scNew.Name   = sc.Name;
                    foreach (MessageTypeMapping mtm in sc.MessageTypeMappings)
                    {
                        if (!sb.MessageTypes.Contains(mtm.Name))
                        {
                            ServiceBroker sbParent = sc.Parent;
                            MessageType   mtp      = sbParent.MessageTypes[mtm.Name];
                            DeploySsbObj(mtp, svrName, dbName, SsbEnum.MessageType, false);
                        }

                        MessageTypeMapping mtmNew = new MessageTypeMapping();
                        mtmNew.Name          = mtm.Name;
                        mtmNew.Parent        = scNew;
                        mtmNew.MessageSource = mtm.MessageSource;
                        scNew.MessageTypeMappings.Add(mtmNew);
                    }

                    if (isEdit)
                    {
                        scNew.Alter();
                    }
                    else
                    {
                        scNew.Create();
                    }

                    break;

                case SsbEnum.Queu:
                    q        = (ServiceQueue)obj;
                    q.Parent = sb;

                    if (isEdit)
                    {
                        q.Alter();
                    }
                    else
                    {
                        q.Create();
                    }

                    break;

                case SsbEnum.Service:
                    serv        = (BrokerService)obj;
                    serv.Parent = sb;

                    if (isEdit)
                    {
                        serv.Alter();
                    }
                    else
                    {
                        serv.Create();
                    }

                    break;

                case SsbEnum.Route:
                    rt        = (ServiceRoute)obj;
                    rt.Parent = sb;

                    if (isEdit)
                    {
                        rt.Alter();
                    }
                    else
                    {
                        rt.Create();
                    }

                    break;

                case SsbEnum.RemoteBinding:
                    bind        = (RemoteServiceBinding)obj;
                    bind.Parent = sb;

                    if (isEdit)
                    {
                        bind.Alter();
                    }
                    else
                    {
                        bind.Create();
                    }

                    break;
                }
            }
            catch (FailedOperationException e) {
                string err = string.Format("{0}", e.InnerException);
                //throw;
            }
            catch (Exception ex) {
                string errx = string.Format("{0}", ex.InnerException);
            }

            finally {
                svr.ConnectionContext.Disconnect();
            }
        }