public static CalcServiceApplication Create(string name, CalcService service, SPIisWebServiceApplicationPool appPool)
        {
            #region validation
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }
            if (appPool == null)
            {
                throw new ArgumentNullException("appPool");
            }
            #endregion

            // create the service application
            CalcServiceApplication serviceApplication = new CalcServiceApplication(name, service, appPool);
            serviceApplication.Update();

            // register the supported endpoints
            serviceApplication.AddServiceEndpoint("http", SPIisWebServiceBindingType.Http);
            serviceApplication.AddServiceEndpoint("https", SPIisWebServiceBindingType.Https, "secure");

            return(serviceApplication);
        }
Exemple #2
0
        private void CreateServiceApplicationProxy(CalcServiceApplication serviceApp)
        {
            // get reference to the installed service proxy
            CalcServiceProxy serviceProxy = SPFarm.Local.ServiceProxies.GetValue <CalcServiceProxy>();

            // create service app proxy
            CalcServiceApplicationProxy serviceAppProxy = new CalcServiceApplicationProxy(
                ServiceAppName.Text + " Proxy",
                serviceProxy,
                serviceApp.Uri);

            serviceAppProxy.Update(true);

            // provision service app proxy
            serviceAppProxy.Provision();

            // start it if it isn't already started
            if (serviceAppProxy.Status != SPObjectStatus.Online)
            {
                serviceAppProxy.Status = SPObjectStatus.Online;
            }
            serviceAppProxy.Update(true);

            // add the proxy to the default group if selected
            if (DefaultServiceApp.Checked)
            {
                SPServiceApplicationProxyGroup defaultGroup = SPServiceApplicationProxyGroup.Default;
                defaultGroup.Add(serviceAppProxy);
                defaultGroup.Update(true);
            }
        }
Exemple #3
0
        private void SetupCalcServiceApp()
        {
            // create a long running op..
            using (SPLongOperation op = new SPLongOperation(this))
            {
                op.Begin();

                try
                {
                    // get reference to the installed service
                    CalcService service = SPFarm.Local.Services.GetValue <CalcService>();

                    // create the service application
                    CalcServiceApplication serviceApp = CreateServiceApplication(service);

                    // if the service instance isn't running, start it up
                    StartServiceInstances();

                    // create service app proxy
                    CreateServiceApplicationProxy(serviceApp);
                }
                catch (Exception e)
                {
                    throw new SPException("Error creating Wingtip Calc service application.", e);
                }
            }
        }
        public SPServiceApplication CreateApplication(string name, Type serviceApplicationType, SPServiceProvisioningContext provisioningContext)
        {
            #region validation
            if (serviceApplicationType != typeof(CalcServiceApplication))
            {
                throw new NotSupportedException();
            }
            if (provisioningContext == null)
            {
                throw new ArgumentNullException("provisioningContext");
            }
            #endregion

            // if the service doesn't already exist, create it
            CalcServiceApplication serviceApp = this.Farm.GetObject(name, this.Id, serviceApplicationType) as CalcServiceApplication;
            if (serviceApp == null)
            {
                serviceApp = CalcServiceApplication.Create(name, this, provisioningContext.IisWebServiceApplicationPool);
            }

            return(serviceApp);
        }
Exemple #5
0
        private CalcServiceApplication CreateServiceApplication(CalcService service)
        {
            // create service app
            CalcServiceApplication serviceApp = CalcServiceApplication.Create(
                ServiceAppName.Text,
                service,
                ApplicationPoolSelection.GetOrCreateApplicationPool());

            serviceApp.Update();

            // start it if it isn't already started
            if (serviceApp.Status != SPObjectStatus.Online)
            {
                serviceApp.Status = SPObjectStatus.Online;
            }

            // configure service app endpoint
            serviceApp.AddServiceEndpoint(string.Empty, SPIisWebServiceBindingType.Http);
            serviceApp.Update(true);

            // now provision the service app
            serviceApp.Provision();
            return(serviceApp);
        }
        protected override void InternalProcessRecord()
        {
            #region validation stuff
            // ensure can hit farm
            SPFarm farm = SPFarm.Local;
            if (farm == null)
            {
                ThrowTerminatingError(new InvalidOperationException("SharePoint farm not found."), ErrorCategory.ResourceUnavailable, this);
                SkipProcessCurrentRecord();
            }

            // ensure can hit local server
            SPServer server = SPServer.Local;
            if (server == null)
            {
                ThrowTerminatingError(new InvalidOperationException("SharePoint local server not found."), ErrorCategory.ResourceUnavailable, this);
                SkipProcessCurrentRecord();
            }

            // ensure can hit service application
            CalcService service = farm.Services.GetValue <CalcService>();
            if (service == null)
            {
                ThrowTerminatingError(new InvalidOperationException("Wingtip Calc Service not found (likely not installed)."), ErrorCategory.ResourceUnavailable, this);
                SkipProcessCurrentRecord();
            }

            // ensure can hit app pool
            SPIisWebServiceApplicationPool appPool = this.ApplicationPool.Read();
            if (appPool == null)
            {
                ThrowTerminatingError(new InvalidOperationException("Application pool not found."), ErrorCategory.ResourceUnavailable, this);
                SkipProcessCurrentRecord();
            }
            #endregion

            // verify a service app doesn't already exist
            CalcServiceApplication existingServiceApp = service.Applications.GetValue <CalcServiceApplication>();
            if (existingServiceApp != null)
            {
                WriteError(new InvalidOperationException("Wingtip Calc Service Application already exists."),
                           ErrorCategory.ResourceExists,
                           existingServiceApp);
                SkipProcessCurrentRecord();
            }

            // create & provision the service app
            if (ShouldProcess(this.Name))
            {
                CalcServiceApplication serviceApp = CalcServiceApplication.Create(
                    this.Name,
                    service,
                    appPool);

                // provision the service app
                serviceApp.Provision();

                // pass service app back to the PowerShell
                WriteObject(serviceApp);
            }
        }