Web Services .Net Sample

Does anyone has a successful (and working) .Net example of how to consume a Web Service? I've tried using the one included in the installation files but I get errors regarding ConfigurationManagementWse and IncidentManagementWse. I wonder if anyone has been able to retrieve information using .Net

 

Thanks,

  • @Jar0625,

    It's recommended to use the restful API instead of the SOAP one.

    And I just created a sample code to request an Incident and/or create a new incident by Rest:

    using System;
    using System.Net;
    
    namespace ConsoleProgram
    {
        public class RestAPI
        {
            private const string baseURL = "">localhost:13951/.../";
    
            static void Main(string[] args)
            {
                RestAPI.GetIncident("IM10002");
                RestAPI.CreateIncident();
                var waitForKey = Console.ReadKey();
            }
    
            private static void GetIncident(string IncidentID)
            {
                string URL = baseURL   "incidents/"   IncidentID;
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
                request.Headers["Accept-Encoding"] = "gzip,deflate";
                request.Headers["Authorization"] = "Basic ZmFsY29uOjE=";
                request.Method = "GET";            
                try
                {
                    using (System.IO.Stream s = request.GetResponse().GetResponseStream())
                    {
                        using (System.IO.StreamReader sr = new System.IO.StreamReader(s))
                        {
                            var jsonResponse = sr.ReadToEnd();
                            Console.WriteLine(String.Format("Response: {0}", jsonResponse));
                            Console.WriteLine("Incident requested");
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.Out.WriteLine("-----------------");
                    Console.Out.WriteLine(e.Message);
                }
            }
            private static void CreateIncident()
            {
                string URL = baseURL   "incidents/ ";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
                request.Headers["Accept-Encoding"] = "gzip,deflate";
                request.Headers["Authorization"] = "Basic ZmFsY29uOjE=";
                request.ContentType = "application/json";
                request.Method = "POST";   
                string jsonData = "{ \t'Incident': \t{       'AlertStatus' : 'updated',       'Area' :'failure',       'Assignee' : 'Incident.Analyst',       'AssignmentGroup': 'Network',       'Category' : 'incident',       'ClosureCode' : 'Solved by Workaround',       'Company' : 'advantage',       'Contact' : 'FALCON, JENNIFER',       'ContactFirstName' :'FALCON',       'ContactLastName' : 'JENNIFER',       'Description' : [ 'test' ],       'Impact' : '2',       'JournalUpdates':  \t    [ '08/04/08 12:54:14 US/Mountain (falcon):',           'test',           '08/04/08 12:54:14 US/Mountain (falcon):',           'test'         ],       'Location':'advantage/North America',       'OpenTime' : '2007-09-02T07:51:00 00:00',       'OpenedBy':'Jurr.Fleijs',       'ProblemType' : 'incident',       'ResolutionFixType' : 'incident',       'SLAAgreementID' : 168,       'Service' : 'CI1001060',       'SiteCategory' : 'incident',       'Solution' : ['Solution by rest api'],       'Status' : 'Work In Progress',       'Subarea' :'function or feature not working',       'TicketOwner' : 'Jurr.Fleijs',       'Title' : 'test',       'UpdatedBy' : 'problem',       'UpdatedTime' : '2008-08-04T12:54:26 00:00',       'Urgency' : '3',       'UserPriority': '3 - Average',       'explanation' : ['test'],       'folder' :'advantage' \t} }";
                try
                {
                    using (System.IO.Stream s = request.GetRequestStream())
                    {
                        using (System.IO.StreamWriter sw = new System.IO.StreamWriter(s))
                            sw.Write(jsonData);
                    }
                    using (System.IO.Stream s = request.GetResponse().GetResponseStream())
                    {
                        using (System.IO.StreamReader sr = new System.IO.StreamReader(s))
                        {
                            var jsonResponse = sr.ReadToEnd();
                            Console.WriteLine(String.Format("Response: {0}", jsonResponse));
                            Console.WriteLine("Incident created");
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.Out.WriteLine("-----------------");
                    Console.Out.WriteLine(e.Message);
                }
            }
        }
    }

    In the test I use username/password falcon/1.

    Let me know if it helps,

    Ling-Yan

  • That kind of worked, but my web services are not showing up on the REST Document Service. Even when the RESTful enabled box is checked. I'd like to use the .WSDL file if it's possible. I run into that "ConfigurationManagementWse" error on the .Net sample that comes with the installation.