Want to get rid of Google Ads, click here.
+ Reply to Thread
Results 1 to 18 of 18

Thread: Working C# Code to create an incident in SC 6.2

  1. #1
    Junior Member
    Join Date
    Feb 2008
    Location
    Toronto, Canada
    Posts
    11

    Cool Working C# Code to create an incident in SC 6.2

    Since there is an utter lack of information on this subject, here is some working code that can be used to create an Incident in ServiceCenter 6.2.

    I have really simplified the dotnetexample code that comes with the machine and I think this is pretty straight forward.

    First, create a web reference to the ServiceCenter machine. this can be done by right clicking on <b> Web References </b> in the solution explorer of Visual Studio and selecting <b> Add Web Reference </b>. In the address field, put in http://<schost>:<scport>/IncidentManagement.wsdl and click GO. I called the web reference im. This is why all the data types that are defined in the WSDL are prefaced with im.

    To call the class, use the following:

    Code:
                im.IncidentManagementWse service = SCFunctions.CreateService();
    
                //SC does not parse new line characters correctly, so 
                //keep the lines of the description in separate strings in
                //the array
                String[] desc = new string[4];
                desc[0] = "Line 1 of description";
                desc[1] = "Line 2 of description";
                desc[2] = "Line 3 of description";
                desc[3] = "Line 4 of description";
                
                im.IncidentInstanceType instance = SCFunctions.SetInstanceValues("DESCRIPTION", "New", "Initial Impact", "Severity", "PrimaryAssignmentGroup", "Contact.Name", desc);
    
                im.CreateIncidentResponse response = SCFunctions.Execute(instance, service);
                Console.WriteLine(response.message);
    here is the SCFunctions class:

    Code:
        class SCFunctions
        {
            // Declarations
            public static im.IncidentManagementWse CreateService()
            {
                im.IncidentManagementWse service = new im.IncidentManagementWse();
                service.Credentials = InitCredentials(service);
                return service;
            }
    
            private const String SCUSERNAME = "USERNAME";
            private const String SCPASSWORD = "PASSWORD";
    
            static CredentialCache InitCredentials(im.IncidentManagementWse svc)
            {
                CredentialCache credentialCache = new CredentialCache();
                NetworkCredential credentials = new NetworkCredential(SCUSERNAME, SCPASSWORD, null);
                credentialCache.Add(new Uri(svc.Url), "Basic", credentials);
                return credentialCache;
            }
    
    
            public static im.IncidentInstanceType SetInstanceValues(String BRIEF_DESCRIPTION, String CATEGORY, 
                                                                    String STATUS, String INITIALIMPACT, 
                                                                    String SEVERITY, String PRIMARYASSIGNMENTGROUP, 
                                                                    String CONTACT, String[] arrDESCRIPTION)
            {
                im.IncidentInstanceType instance = new im.IncidentInstanceType(); 
                
                String sValue = null;
                im.StringType stringType = null;
    
                sValue = BRIEF_DESCRIPTION;
                stringType = new im.StringType();
                stringType.Value = sValue;
                instance.BriefDescription = stringType;
    
                sValue = CATEGORY;
                stringType = new im.StringType();
                stringType.Value = sValue;
                instance.Category = stringType;
    
                sValue = STATUS;
                stringType = new im.StringType();
                stringType.Value = sValue;
                instance.status = stringType;
    
                sValue = INITIALIMPACT;
                stringType = new im.StringType();
                stringType.Value = sValue;
                instance.InitialImpact = stringType;
    
                sValue = SEVERITY;      
                stringType = new im.StringType();
                stringType.Value = sValue;
                instance.Severity = stringType;
    
                sValue = PRIMARYASSIGNMENTGROUP;
                stringType = new im.StringType();
                stringType.Value = sValue;
                instance.PrimaryAssignmentGroup = stringType;
    
                sValue = CONTACT;
                stringType = new im.StringType();
                stringType.Value = sValue;
                instance.Contact = stringType;
    
                im.IncidentInstanceTypeIncidentDescription desc = new im.IncidentInstanceTypeIncidentDescription();
                int DescCount = arrDESCRIPTION.GetUpperBound(0);
    
                im.StringType[] stringTypes = new im.StringType[DescCount + 1];
                for (int ctr = 0; ctr <= DescCount; ctr++)
                {
                    sValue = arrDESCRIPTION[ctr];
                    stringType = new im.StringType();
                    stringType.Value = sValue;
                    stringTypes[ctr] = stringType;
                }
    
                im.IncidentInstanceTypeIncidentDescription actions = new im.IncidentInstanceTypeIncidentDescription();
                actions.IncidentDescription = stringTypes;
                instance.IncidentDescription = actions;
    
                return instance;
            }
    
            public static im.CreateIncidentResponse Execute(im.IncidentInstanceType instance,
                                                            im.IncidentManagementWse service)
            {
                im.IncidentModelType model = new im.IncidentModelType();
                im.IncidentKeysType keys = new im.IncidentKeysType();
                im.CreateIncidentRequest request = new im.CreateIncidentRequest();
                im.CreateIncidentResponse response = new im.CreateIncidentResponse();
                try
                {
                    model.keys = keys;
                    model.instance = instance;
                    request.model = model;
                    response = service.CreateIncident(request);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return response;
                }
    
                return response;
            }
        }
    Hopefully this will help someone to not have to schlep as much as I did to get this working. Please let me know if you have any questions or comments.

    I am putting similar code together for Incident Updates. Once complete I will post here.

    Have a good one..

    Bzzzz

  2. #2
    Junior Member knst's Avatar
    Join Date
    Feb 2008
    Location
    Moscow, Russia
    Posts
    7

    Default

    I'm currently working on integration solution for SM7 and customer's CRM. I've already implemented create/delete/retrieve operations for Incident, Interaction and Interaction Activity over Web Services (I can share the code if you are interested in it). But i stuck with Incident activity... Only operation that works is retrieve. On any try to create a new one I get "User is not authorized" even with admin credentials. I've tried to use new WS interface and legacy one, result is always the same.
    I'll be thankful for any ideas.

  3. #3
    Junior Member
    Join Date
    Feb 2008
    Location
    Toronto, Canada
    Posts
    11

    Default

    I am using ServiceCenter 6.2 not ServiceManager but i understand they are similar in the WSDL implementation.

    I had the same problem and the only way i was able to fix was to use the FALCON login. Try using FALCON and see if you still get the same error.

    I would be happy to look at your code to try to assist though.

    ..Darren

    Quote Originally Posted by knst View Post
    I'm currently working on integration solution for SM7 and customer's CRM. I've already implemented create/delete/retrieve operations for Incident, Interaction and Interaction Activity over Web Services (I can share the code if you are interested in it). But i stuck with Incident activity... Only operation that works is retrieve. On any try to create a new one I get "User is not authorized" even with admin credentials. I've tried to use new WS interface and legacy one, result is always the same.
    I'll be thankful for any ideas.

  4. #4
    Senior Member glg's Avatar
    Join Date
    Aug 2004
    Location
    Chicago, IL, USA
    Posts
    715

    Default

    check for capability word "SOAP API". falcon has it OOB.

  5. #5
    Junior Member
    Join Date
    Feb 2008
    Location
    Toronto, Canada
    Posts
    11

    Default

    That sounds great... In my testing I did have 'SOAP API' on the profile that was attempting to create the incident and it did not work, a change to FALCON with no additional code change fixed the issue.

    I had opened a case with HP support and after a few webex sessions and head scratches they were unable to help and closed the ticket as unresolved.

    .D

    Quote Originally Posted by glg View Post
    check for capability word "SOAP API". falcon has it OOB.

  6. #6
    Junior Member knst's Avatar
    Join Date
    Feb 2008
    Location
    Moscow, Russia
    Posts
    7

    Default

    Quote Originally Posted by bodybuzz View Post
    I am using ServiceCenter 6.2 not ServiceManager but i understand they are similar in the WSDL implementation.

    I had the same problem and the only way i was able to fix was to use the FALCON login. Try using FALCON and see if you still get the same error.

    I would be happy to look at your code to try to assist though.

    ..Darren


    We are using manually created in SM web service for dataaccess operations (it helps to avoid conflicts with customization of SM being implemented by other team), besides there is no CreateIncidentActivity method in API WS.
    This WS is quite simple and is very alike to the ones from native WS API.
    SmServiceClient is WCF proxy generated with SvcUtil.exe.
    Only trick here is slightly changed security section of binding in config:

    Code:
              <security mode="TransportCredentialOnly">
                <transport clientCredentialType="Basic" proxyCredentialType="None"
                  realm="" />
              </security>
    Here is the code of test reproducing the issue I've posted about. It takes existing activity, changes id and incident in retrieved object and posts it back to SM with create requests.

    Code:
            [Test]
            public void CreateIncidentActivityTest()
            {
                SmServiceClient clnt=new SmServiceClient();
                clnt.ClientCredentials.UserName.UserName = "falcon";
                clnt.ClientCredentials.UserName.Password = "";
    
    
                RetrieveSmIncActivityRequest request1 = new RetrieveSmIncActivityRequest();
                request1.SmIncActivity=new SmIncActivity();
                request1.SmIncActivity.ActivityId = new StringType();
                request1.SmIncActivity.ActivityId.Value = "001A825";
                RetrieveSmIncActivityResponse resp1 = clnt.RetrieveSmIncActivity(request1);
    
    
                CreateSmIncActivityRequest request = new CreateSmIncActivityRequest();
                request.SmIncActivity = resp1.SmIncActivity;
                    
                request.SmIncActivity.ActivityId = null;
                request.SmIncActivity.IncidentId = new StringType();
                request.SmIncActivity.IncidentId.Value = "IM10280";
                CreateSmIncActivityResponse response = clnt.CreateSmIncActivity(request);
                Console.Write(response.messages[0].Value);
                Assert.AreEqual("SUCCESS",response.status);
            }
    Retrieve of existing activity passes ok, but creation of new one fails

    test output is:

    IncidentActivityTest.CreateIncidentActivityTest : Failed

    User falcon does not have authorization to perform the action: add
    NUnit.Framework.AssertionException:
    expected: <"SUCCESS">
    but was: <FAILURE>
    at NUnit.Framework.Assert.AreEqual(Object expected, Object actual)
    at IncidentActivityTest.IncidentActivityTest.CreateIn cidentActivityTest() in IncidentActivityTest.cs:line 32



    As you see I'm using FALCON credentials. Any ideas?

  7. #7
    Junior Member
    Join Date
    Feb 2008
    Location
    Toronto, Canada
    Posts
    11

    Question

    Code:
            [Test]
            public void CreateIncidentActivityTest()
            {
                SmServiceClient clnt=new SmServiceClient();
                clnt.ClientCredentials.UserName.UserName = "falcon";
                clnt.ClientCredentials.UserName.Password = "";
    I am sure I am being overly simplistic... But isn't the falcon username supposed to be capitalized? --> FALCON

    Perhaps this is not the case in ServiceManager..

    .D

  8. #8
    Junior Member knst's Avatar
    Join Date
    Feb 2008
    Location
    Moscow, Russia
    Posts
    7

    Default

    I've tryed both falcon and FALCON. FALCON gives the same result (absense of result strictly speaking ).

  9. #9
    Junior Member knst's Avatar
    Join Date
    Feb 2008
    Location
    Moscow, Russia
    Posts
    7

    Default

    Problem is solved. Magic spell:
    - go to Tailoring/Format Control
    - open activities table
    - select privileges tab
    - set add to true.

  10. #10
    Junior Member
    Join Date
    Dec 2007
    Posts
    17

    Default

    Quote Originally Posted by knst View Post
    Problem is solved. Magic spell:
    - go to Tailoring/Format Control
    - open activities table
    - select privileges tab
    - set add to true.
    Probably should set the privileges to something like:

    index("SOAP API", $lo.ucapex)>0

    That way, you're only changing it for access through web services.

    Also, would you mind sharing the web services code you have? I'm trying to do something almost identical to what you're doing. Currently I'm using much older DDE scripts for automation and would like to get around to converting them to web services as part of the upgrade to Service Manager.

    Problem is, I've got zero experience working with web services, so sample code is a huge help.

    I'll PM the E-mail.

  11. #11
    Junior Member knst's Avatar
    Join Date
    Feb 2008
    Location
    Moscow, Russia
    Posts
    7

    Default

    There is no such thing as Web Service code in terms of SM. You need to create Web Services using SM client or use native ones. There is a way to import/exoport SM customization, but our current SM customization realizes customer specific business rules thus it hardly can be reused, besides I suppose our customer would not be happy if I share it. I think you'd better to try using native services first.
    Problems discussed in this thread are related to consuming SM web services. If you will
    have problems with this feel free to give a question here. I'll try to answer. Samples of consuming SM WS are provided with SM distrib and something is given by bodybuzz .

  12. #12
    Junior Member Grom's Avatar
    Join Date
    Mar 2008
    Location
    Hamburg
    Posts
    5

    Thumbs up Thank you, Danke!

    Thank you, Danke!

  13. #13
    Senior Member
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    291

    Default

    Hello,

    does anybody have a sample for MIME (or MTOM - SM7) attachments?

    Greets,

    Lars

  14. #14
    Junior Member knst's Avatar
    Join Date
    Feb 2008
    Location
    Moscow, Russia
    Posts
    7

    Default

    I've wasted last week trying to obtain attachments from SM7. It looks like the respond it sends does not fit standard... WCF fails to process respond messages with exception messages like "MTOM messages must have type 'application/xop+xml'" (soap12)
    and "MIME part with Content-ID '<http://tempuri.org/0>' not found" soap11.

  15. #15
    Junior Member t_v_33's Avatar
    Join Date
    Apr 2008
    Location
    Toronto
    Posts
    1

    Default

    Sorry... is there an equivalent table in SC 6.2 to your SM activities table? I understand what you're setting to true but unclear as to what the activities table is for and what the SC equivalent table is.

  16. #16
    Junior Member knst's Avatar
    Join Date
    Feb 2008
    Location
    Moscow, Russia
    Posts
    7

    Default

    I have never seen SC (and hope I'll never see SM after i finish with current project - it is unstable, buggy, compiled with WTF patterns thing)
    Activity is actually a kind of log, each time SM performs some with it's objects , it creates activity (type + description), in some cases it requires activity to be created by user (i.e. if user closes interaction he must create activity with some text comments to this action )

  17. #17
    Administrator tommy's Avatar
    Join Date
    Nov 2001
    Location
    Copenhagen
    Posts
    4,272

    Default

    Does anybody have an idea how difficult it will be to do this in Delphi ? I know nothing about C# and even less about WebServices.
    Best regards Tommy
    Blog - - ITIL certified - Accredited Integration Specialist – HP OpenView Service Management

    Want to keep this site alive? Consider making a donation. Click here.

  18. #18
    Junior Member
    Join Date
    Jun 2009
    Posts
    3

    Default

    Quote Originally Posted by knst View Post
    I'm currently working on integration solution for SM7 and customer's CRM. I've already implemented create/delete/retrieve operations for Incident, Interaction and Interaction Activity over Web Services (I can share the code if you are interested in it). But i stuck with Incident activity... Only operation that works is retrieve. On any try to create a new one I get "User is not authorized" even with admin credentials. I've tried to use new WS interface and legacy one, result is always the same.
    I'll be thankful for any ideas.
    Hey,

    Can you share your code to create interactions??

    Thank you!!

    Filipe

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts