Highlighted
karges Frequent Contributor.
Frequent Contributor.
562 views

consuming HPSM web service using c#

Hi Below is my App.config file and a c# console application code (added web reference to HPSM web services) , any help would be appreaciated. the same i have achevied using java , but my requirement needs the same should be done in .net. how to do ? 

  1. once my first question above is resolved i have one more question also !!! i need to write soap interceptors equalent in .net. i java i have writttent soap interceptors to add addachment to incident module of HPSM

  2. my third million dollar question is what is this SHERPA ???? i know its meanign in social  terms , what is to do with an ITSM tool like HPSM!! 

 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup> 
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>

<binding name="Sherpa" >
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>

</bindings>
<client>
<endpoint address="http://XXXXXXXXX.XXX.XXX.com:XXXX/SM/7/ws"
binding="basicHttpBinding" bindingConfiguration="Sherpa" contract="sherpa_service.Sherpa"
name="Sherpa" />
</client>
</system.serviceModel>
</configuration>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Windows.Forms;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
sherpa_service.SherpaInstanceType create_instance = new sherpa_service.SherpaInstanceType();
sherpa_service.StringType category = new sherpa_service.StringType();
sherpa_service.StringType assignment_group = new sherpa_service.StringType();
sherpa_service.StringType assignee = new sherpa_service.StringType();
sherpa_service.StringType area = new sherpa_service.StringType();
sherpa_service.StringType sub_area = new sherpa_service.StringType();
sherpa_service.StringType impact = new sherpa_service.StringType();
sherpa_service.StringType urgency = new sherpa_service.StringType();
sherpa_service.StringType contact_number = new sherpa_service.StringType();
sherpa_service.StringType title = new sherpa_service.StringType();
sherpa_service.StringType email_id = new sherpa_service.StringType();
sherpa_service.StringType[] desc = new sherpa_service.StringType[3];
desc[0] = new sherpa_service.StringType();
desc[0].Value = "sample description from .net";
sherpa_service.SherpaInstanceTypeDescription description = new sherpa_service.SherpaInstanceTypeDescription();
description.Description = desc;

 


category.Value = "Finance / Treasury / Tax Apps";
assignment_group.Value = "Procure to Pay";
area.Value = "Finance Apps";
sub_area.Value = "concur";
assignee.Value = "apadiyar";
email_id.Value = "seethak@non.agilent.com";
contact_number.Value = "9884525412";

create_instance.ContactNumber = contact_number;
create_instance.EXternalEmail = email_id;
create_instance.Category = category;
create_instance.AssignmentGroup = assignment_group;
create_instance.Assignee = assignee;
create_instance.Area = area;
create_instance.Subarea = sub_area;
create_instance.Description = description;

sherpa_service.SherpaKeysType create_key = new sherpa_service.SherpaKeysType();
sherpa_service.SherpaModelType create_model = new sherpa_service.SherpaModelType();
sherpa_service.CreateSherpaRequest1 create_incident = new sherpa_service.CreateSherpaRequest1();

create_model.keys = create_key;
create_model.instance = create_instance;
create_incident.CreateSherpaRequest = new sherpa_service.CreateSherpaRequest();
create_incident.CreateSherpaRequest.model = create_model;
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress myEndpoint = new EndpointAddress("http://wcostcswebtst01.cos.agilent.com:13080/SM/7/ws");
var myChannelFactory = new ChannelFactory<sherpa_service.Sherpa>(binding, myEndpoint);

var credentialBehaviour = myChannelFactory.Endpoint.Behaviors.Find<System.ServiceModel.Description.ClientCredentials>();
credentialBehaviour.UserName.UserName = "xxxx";
credentialBehaviour.UserName.Password = "xxxx";

sherpa_service.Sherpa client = null;

try
{
myChannelFactory.Credentials.UserName.UserName = "xxxx";
myChannelFactory.Credentials.UserName.Password = "xxxx";
client = myChannelFactory.CreateChannel();
sherpa_service.CreateSherpaResponse1 brands = client.CreateSherpa(create_incident);

System.Console.ReadLine();
((ICommunicationObject)client).Close();
}
catch (Exception ex)
{
if (client != null)
{
MessageBox.Show(ex.ToString());
System.Console.ReadLine();
}
}
/*BasicHttpBinding binding = new BasicHttpBinding();
binding.SendTimeout = TimeSpan.FromSeconds(25);

binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType =
HttpClientCredentialType.Basic;
EndpointAddress address = new EndpointAddress("http://xxxxxxx.xx.xx.com:xxxx/SM/7/ws");

ChannelFactory<sherpa_service.Sherpa> factory =
new ChannelFactory<sherpa_service.Sherpa>(binding, address);
factory.Credentials.UserName.UserName = "xx";
factory.Credentials.UserName.Password = "xx";
sherpa_service.Sherpa proxy = factory.CreateChannel();
sherpa_service.CreateSherpaResponse1 respo = proxy.CreateSherpa(create_incident);
Console.WriteLine(respo);*/
}
}
}

Below is the exception i got : 

 

=============================

System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic realm="CASM"'. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---

Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest request, HttpWebResponse response, WebException responseException, HttpChannelFactory`1 factory)
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at ConsoleApp1.sherpa_service.Sherpa.CreateSherpa(CreateSherpaRequest1 request)
at ConsoleApp1.Program.Main(String[] args) in C:\Users\seethark\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 75

 

Below is my stack over flow question which was marked initially duplicate but then after i explained the issue correctly they accepted its a new kind 

stack over flow linkan

MSDN whcich explaines about soap headers but this also did not help much

 

0 Likes
3 Replies
Micro Focus Expert
Micro Focus Expert

Re: consuming HPSM web service using c#

Hello karges,
Hope you are doing well.

Thanks for reaching Service Manager Forum!

Please refer to the following link to obtain SM 9.30 Web Services Guide.
https://softwaresupport.softwaregrp.com/km/KM469500/SM_WebServices_Best_Practices.pdf

9.40 Codeless:
https://softwaresupport.softwaregrp.com/km/KM01314028/HP_Service_Manager_Web_Services_codeless.pdf

9.40 Classic:
https://softwaresupport.softwaregrp.com/km/KM01314029/HP_Service_Manager_Web_Services_classic.pdf

Hope this helps.

Best regards!

If you find that this or any other post resolves your issue, please be sure to mark it as an accepted solution. If you are satisfied with anyone’s response please remember to give them a LIKE by clicking on the Thumb and show your appreciation.
0 Likes
karges Frequent Contributor.
Frequent Contributor.

Re: consuming HPSM web service using c#

Hi Jose_A_SM ,

Really thanks for the reply out ofthe three documents , the second one was having some usefull information . in that from page number 90 onwards , it is having how to information on how to write custom web servie client applications especially page number 94 has this detail of the location of the sample code   (\webservices\sample\sc62webservices ) .

but to acces this location either i should have access to the directory where the  SM9 is installed in the SM9 server , or the team which has access to the folder shold give access to that folder. i am trying to get access to this folder . but it is unlikely that i will get access , anyway i am trying my level best. 

meanwhile , i need some example which can connect and create and incident with attachment in c# and also to downlaod attachments from incident. 

NOTE : for the attachment operations i also readin  in the same pdf that i should install WSE 2.0 SP2 in the system where custom web service client is being wrritten , but am getting an error while installing . attched is that screen shot . while this problem is something secondry am just saying that this is also something very muchn needed forme. am looking out how to sovle this

Refereed this link but not much of use

0 Likes
karges Frequent Contributor.
Frequent Contributor.

Re: consuming HPSM web service using c#

Hi 

i have kind of sovled ther issue , below peace of code actually creating ticket , but am not able to locate the incident from front end , so is it actually creating incident or whatis happening am not sure . to test whether this appraoch connects to the back end using web services , i tried to retrieve  details of one incident , it retreved correctly like some of the feilds under which iincident is created. so this approach is some how working but am not sure why its not creating incident ?

Below is the piece of code of creating incident , 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Windows.Forms;
namespace ConsoleApp1
{
    class Program
    {
     
        static void Main(string[] args)
        {

            Retrieve ret_in = new Retrieve();
            ret_in.get_det(); // this line of code retrieves details of an incident. the code for this is in the following section 
            SherpaInstanceType create_instance = new SherpaInstanceType();
            StringType category = new StringType();
            StringType assignment_group = new StringType();
            StringType assignee = new StringType();
            StringType area = new StringType();
            StringType sub_area = new StringType();
            StringType impact = new StringType();
            StringType urgency = new StringType();
            StringType contact_number = new StringType();
            StringType title = new StringType();
            StringType email_id = new StringType();
            StringType[] desc = new StringType[3];
            desc[0] = new StringType();
            desc[0].Value = "sample description from .net";
            SherpaInstanceTypeDescription description = new SherpaInstanceTypeDescription();
            description.Description = desc;




            category.Value = "Finance / Treasury / Tax Apps";
            assignment_group.Value = "Procure to Pay";
            area.Value = "Finance Apps";
            sub_area.Value = "concur";
            assignee.Value = "apadiyar";
            email_id.Value = "seethak@non.xxxxxxx.com";
            contact_number.Value = "9884525412";

            create_instance.ContactNumber = contact_number;
            create_instance.EXternalEmail = email_id;
            create_instance.Category = category;
            create_instance.AssignmentGroup = assignment_group;
            create_instance.Assignee = assignee;
            create_instance.Area = area;
            create_instance.Subarea = sub_area;
            create_instance.Description = description;

           SherpaKeysType create_key = new SherpaKeysType();
            SherpaModelType create_model = new SherpaModelType();
          CreateSherpaRequest create_incident = new CreateSherpaRequest();

            create_model.keys = create_key;
            create_model.instance = create_instance;
            create_incident.model = create_model;
            BasicHttpBinding binding = new BasicHttpBinding();
            EndpointAddress myEndpoint = new EndpointAddress("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            Sherpa sherpa_obj = new Sherpa();
            Uri uri = new Uri("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

            System.Net.NetworkCredential cre = new System.Net.NetworkCredential( "xxxxx", "xxxxx");

            System.Net.CredentialCache myCache = new System.Net.CredentialCache();
            myCache.Add(uri, "Basic", cre);
            sherpa_obj.Credentials = myCache;
             CreateSherpaResponse respo =  sherpa_obj.CreateSherpa(create_incident);

            System.Windows.Forms.MessageBox.Show(respo.model.keys.IncidentID.Value.ToString());

          
        }
    }
}

Below is the code to retrieve the incident details . this peice of code correctly retreving the incident details.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Windows.Forms;
namespace ConsoleApp1
{
    class Retrieve
    {
        public void get_det()
        {
            Sherpa sherpa_obj = new Sherpa();
            Uri uri = new Uri("xxxxxxxxxxxxxxxxxxxxxxxxxxxx.com:13080/SM/7/ws");

            System.Net.NetworkCredential cre = new System.Net.NetworkCredential("xxxx", "xxxxx");

            System.Net.CredentialCache myCache = new System.Net.CredentialCache();
            myCache.Add(uri, "Basic", cre);
            sherpa_obj.Credentials = myCache;
            RetrieveSherpaRequest ret_inc = new RetrieveSherpaRequest();
            SherpaInstanceType search_instance = new SherpaInstanceType();
            StringType inc_id = new StringType();
            inc_id.Value = "IM66913777";
            search_instance.IncidentID = inc_id;
            SherpaKeysType search_key = new SherpaKeysType();
            SherpaModelType search_model = new SherpaModelType();
            search_model.keys = search_key;
            search_model.instance = search_instance;
            ret_inc.model = search_model;
            RetrieveSherpaResponse respo =  sherpa_obj.RetrieveSherpa(ret_inc);
            System.Windows.Forms.MessageBox.Show(respo.model.instance.Category.ToString());




        }

    }
}

 

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.