Пример #1
0
 /// <summary>
 /// A private function used by NewServer for validation purposes.
 /// </summary>
 /// <param name="client">A ServiceNOW soapclient</param>
 /// <param name="Name">The name property of the item</param>
 /// <returns>true if the item exists, false if it doesn't</returns>
 private static bool itemExist(ServiceNowSoapClient client, string Name)
 {
     try
     {
         getRecords gRecords = new getRecords();
         gRecords.name = Name;
         getRecordsResponseGetRecordsResult[] gResults = client.getRecords(gRecords);
         foreach (getRecordsResponseGetRecordsResult gResult in gResults)
         {
             if (gResult.name == Name)
             {
                 //
                 // this item already exists
                 //
                 return true;
             }
         }
         //
         // No match found
         //
         return false;
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return true;
     }
 }
        public static ContentResult get(string numberOfRecords)
        {
            // Get credentials to use for this request.
            string username = ConfigurationManager.AppSettings["snUsername"];
            string password = ConfigurationManager.AppSettings["snPassword"];

            //initialize the client
            ServiceNowSoapClient client = new ServiceNowSoapClient();

            //pass the credentials using basic auth
            client.ClientCredentials.UserName.UserName = username;
            client.ClientCredentials.UserName.Password = password;

            //set the query parameters
            getRecords getReq = new getRecords();
            getReq.__limit = numberOfRecords;
            getReq.__exclude_columns = ConfigurationManager.AppSettings["cmdb_ci_ExcludedColumns"];
            getReq.sys_created_on = " >= 2015-10-01";
            getReq.__order_by_desc = "sys_created_on";

            //get the response
            getRecordsResponseGetRecordsResult[] result = client.getRecords(getReq);

            //return the result
             return new ContentResult { Content = JsonConvert.SerializeObject(result), ContentType = "application/json" };
        }
Пример #3
0
        /// <summary>
        /// A private function to create the soapclient to communicate with ServiceNOW
        /// </summary>
        /// <param name="UserName">The API Username</param>
        /// <param name="Password">The API Password</param>
        /// <returns>A ServiceNow SoapClient object</returns>
        private static ServiceNowSoapClient soapClient(string UserName, string Password, string ServiceNowUrl)
        {
            try
            {
                EndpointAddress endpoint = new EndpointAddress(new Uri(ServiceNowUrl));
                WSHttpBinding   binding  = new WSHttpBinding();

                binding.Name = "ServiceNowSoap";
                binding.MaxReceivedMessageSize = 65536;
                binding.Security.Mode          = SecurityMode.Transport;
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
                binding.Security.Transport.ProxyCredentialType  = HttpProxyCredentialType.Basic;
                binding.Security.Message.ClientCredentialType   = MessageCredentialType.UserName;

                ServiceNowSoapClient soapClient = new ServiceNowSoapClient(binding, endpoint);
                soapClient.ClientCredentials.UserName.UserName = UserName;
                soapClient.ClientCredentials.UserName.Password = Password;

                return(soapClient);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
Пример #4
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            // Note: Please enable SOAP/REST services in your SNow dev instance table(s), Also,
            // Go to system web services --> properties -> enable the 3rd option from the bottom.(This property sets the elementFormDefault attribute of the embedded XML schema to the value of unqualified)
            ServiceNowSoapClient client = new ServiceNowSoapClient();

            client.ClientCredentials.UserName.UserName = "******"; // makhan8 have SOAP role in SNow.
            client.ClientCredentials.UserName.Password = "******";

            insert         newRecord      = new insert();
            insertResponse insertResponse = new insertResponse();

            newRecord.first_name   = "Jackson";
            newRecord.last_name    = "Chris";
            newRecord.phone_number = "911-911-9999";
            //newRecord.number = "CUS3048232";
            try
            {
                insertResponse = client.insert(newRecord);
                TextBox1.Text  = insertResponse.sys_id;
            }
            catch (Exception ex)
            {
                TextBox1.Text = ex.Message;
            }
            finally { client.Close(); }
        }
Пример #5
0
 /// <summary>
 /// A private function used by NewServer for validation purposes.
 /// </summary>
 /// <param name="client">A ServiceNOW soapclient</param>
 /// <param name="Name">The name property of the item</param>
 /// <returns>true if the item exists, false if it doesn't</returns>
 private static bool itemExist(ServiceNowSoapClient client, string Name)
 {
     try
     {
         getRecords gRecords = new getRecords();
         gRecords.name = Name;
         getRecordsResponseGetRecordsResult[] gResults = client.getRecords(gRecords);
         foreach (getRecordsResponseGetRecordsResult gResult in gResults)
         {
             if (gResult.name == Name)
             {
                 //
                 // this item already exists
                 //
                 return(true);
             }
         }
         //
         // No match found
         //
         return(false);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(true);
     }
 }
Пример #6
0
        /// <summary>
        /// A private function to create the soapclient to communicate with ServiceNOW
        /// </summary>
        /// <param name="UserName">The API Username</param>
        /// <param name="Password">The API Password</param>
        /// <returns>A ServiceNow SoapClient object</returns>
        private static ServiceNowSoapClient soapClient(string UserName, string Password, string ServiceNowUrl)
        {
            try
            {
                EndpointAddress endpoint = new EndpointAddress(new Uri(ServiceNowUrl));
                WSHttpBinding binding = new WSHttpBinding();

                binding.Name = "ServiceNowSoap";
                binding.MaxReceivedMessageSize = 65536;
                binding.Security.Mode = SecurityMode.Transport;
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
                binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;
                binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;

                ServiceNowSoapClient soapClient = new ServiceNowSoapClient(binding, endpoint);
                soapClient.ClientCredentials.UserName.UserName = UserName;
                soapClient.ClientCredentials.UserName.Password = Password;

                return soapClient;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return null;
            }
        }
 public void AttachFile(string UID, string path)
 {
     ServiceNowSoapClient ServiceNowReference = new ServiceNowSoapClient();
     var file = File.ReadAllBytes(path);
     var insert = new insert
     {
         agent = "AttachmentCreator",
         topic = "AttachmentCreator",
         name = path.Substring(path.LastIndexOf('\\') + 1) + ":" + GetContentType(path.Substring(path.LastIndexOf('.'))),
         source = "incident:" + UID,
         payload = Convert.ToBase64String(file)
     };
     var res = ServiceNowReference.insert(insert);
 }
Пример #8
0
        /// <summary>
        /// A private function to create the soapclient to communicate with ServiceNOW
        /// </summary>
        /// <param name="UserName">The API Username</param>
        /// <param name="Password">The API Password</param>
        /// <param name="ServiceNowUrl">The ServiceNOW Url</param>
        /// <returns>A ServiceNow SoapClient object</returns>
        private static ServiceNowSoapClient soapClient(string UserName, string Password, string ServiceNowUrl)
        {
            try
            {
                EndpointAddress endpoint = new EndpointAddress(new Uri(ServiceNowUrl));
                ServiceNowSoapClient soapClient = new ServiceNowSoapClient("ServiceNowSoap", endpoint);
                soapClient.ClientCredentials.UserName.UserName = UserName;
                soapClient.ClientCredentials.UserName.Password = Password;

                return soapClient;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return null;
            }
        }
Пример #9
0
        /// <summary>
        /// Get one or more incidents from ServiceNOW
        /// </summary>
        /// <param name="Credential">A NetworkCredential object that gets passed to the soap client for authentication</param>
        /// <param name="Incident">A getRecrods object that contains the data to be retreived from ServiceNOW</param>
        /// <returns>A getRecordsResponseGetRecordsResult array of incidents</returns>
        public static getRecordsResponseGetRecordsResult[] GetIncident(NetworkCredential Credential, getRecords Incident, string ServiceNowUrl)
        {
            try
            {
                string userName             = Credential.UserName;
                string userPass             = Credential.Password;
                ServiceNowSoapClient client = soapClient(userName, userPass, ServiceNowUrl);

                getRecordsResponseGetRecordsResult[] result = client.getRecords(Incident);

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #10
0
        /// <summary>
        /// A private function to create the soapclient to communicate with ServiceNOW
        /// </summary>
        /// <param name="UserName">The API Username</param>
        /// <param name="Password">The API Password</param>
        /// <returns>A ServiceNow SoapClient object</returns>
        private static ServiceNowSoapClient soapClient(string UserName, string Password, string ServiceNowUrl)
        {
            try
            {
                EndpointAddress      endpoint   = new EndpointAddress(new Uri(ServiceNowUrl));
                ServiceNowSoapClient soapClient = new ServiceNowSoapClient("ServiceNowSoap", endpoint);
                soapClient.ClientCredentials.UserName.UserName = UserName;
                soapClient.ClientCredentials.UserName.Password = Password;

                return(soapClient);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
Пример #11
0
        /// <summary>
        /// This function creates a new incident in ServiceNOW
        /// </summary>
        /// <param name="Credential">A credential object that gets passed to the soap client for authentication</param>
        /// <param name="Incident">An insert object that contains the data to be inserted into ServiceNOW</param>
        /// <returns>An insertResponse object containing data returned from ServiceNOW</returns>
        public static insertResponse NewIncident(NetworkCredential Credential, insert Incident, string ServiceNowUrl)
        {
            try
            {
                string userName             = Credential.UserName;
                string userPass             = Credential.Password;
                ServiceNowSoapClient client = soapClient(userName, userPass, ServiceNowUrl);

                insertResponse response = new insertResponse();

                response = client.insert(Incident);
                return(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #12
0
        /// <summary>
        /// This function inserts a server into the ServiceNow CI Database
        /// </summary>
        /// <param name="Credential">A NetworkCredential object that gets passed to the soap client for authentication</param>
        /// <param name="Server">An insert object that contains the data to be inserted into ServiceNOW</param>
        /// <returns>An insertResponse object containing data returned from ServiceNOW</returns>
        public static insertResponse NewServer(NetworkCredential Credential, insert Server, string ServiceNowUrl)
        {
            try
            {
                string userName             = Credential.UserName;
                string userPass             = Credential.Password;
                ServiceNowSoapClient client = soapClient(userName, userPass, ServiceNowUrl);

                insertResponse response = new insertResponse();

                if (!(itemExist(client, Server.name)))
                {
                    response = client.insert(Server);
                }
                return(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }