Highlighted
Contributor.
Contributor.
540 views

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,

0 Likes
2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Web Services .Net Sample

@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 = "http://localhost:13951/SM/9/rest/";

        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

0 Likes
Highlighted
Contributor.
Contributor.

Re: Web Services .Net Sample

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.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.