Re: Attachemnts throught webservice (Createincidentrequest) (1094 Views)
Reply
Trusted Contributor
Andy_ABB
Posts: 157
Registered: ‎03-22-2012
Message 1 of 13 (1,429 Views)

Attachemnts throught webservice (Createincidentrequest)

Hi

 

Ive got problems with sending attachment to HP SM 9.30. I wrote this code:

 

 

public static IncidentInstanceType SetInstanceValues(String BRIEF_DESCRIPTION, String CATEGORY, String INITIALIMPACT, String SEVERITY, String PRIMARYASSIGNMENTGROUP, String SUBCATEGORY, String[] arrDESCRIPTION, String PRODUCTTYPE, String SERVICE, String[] UPDATE, String OPENED_BY, String code, String[] solution)
            {
                IncidentInstanceType instance = new IncidentInstanceType();
                String sValue = null;
                StringType stringType = null;

                byte[] buffer = null;
                FileStream fs = new FileStream("C:\\Users\\plansyn\\Desktop\\Untitled.bmp", FileMode.Open, FileAccess.Read, FileShare.Read);
                buffer = new byte[fs.Length];
                fs.Read(buffer, 0, (int)fs.Length);
                InMan.AttachmentType Attach = null;
                Attach = new InMan.AttachmentType();
                FileInfo file = new FileInfo("C:\\Users\\plansyn\\Desktop\\Untitled.bmp");
                FileStream streamFile = file.OpenRead();
                Attach.href = "C:\\Users\\plansyn\\Desktop\\Untitled.bmp";
                Attach.action = "add";
                Attach.name = "Untitled.bmp";
                Attach.lenSpecified = true;
                Attach.len = buffer.Length;
                Attach.type = file.Extension;
                Attach.contentId = "asdgd";
                Attach.attachmentType = "image/jpg";
                instance.attachments = new AttachmentType[] { Attach };


                sValue = code;
                stringType = new StringType();
                stringType.Value = sValue;
                instance.Status = stringType;


                sValue = OPENED_BY;
                stringType = new StringType();
                stringType.Value = sValue;
                instance.OpenedBy = stringType;



                sValue = BRIEF_DESCRIPTION;
                stringType = new StringType();
                stringType.Value = sValue;
                instance.Title = stringType;

                sValue = CATEGORY;
                stringType = new StringType();
                stringType.Value = sValue;
                instance.Category = stringType;

                sValue = INITIALIMPACT;
                stringType = new StringType();
                stringType.Value = sValue;
                instance.Priority = stringType;

                sValue = INITIALIMPACT;
                stringType = new StringType();
                stringType.Value = sValue;
                instance.Impact = stringType;

                sValue = SEVERITY;
                stringType = new StringType();
                stringType.Value = sValue;
                instance.Urgency = stringType;

                sValue = PRIMARYASSIGNMENTGROUP;
                stringType = new StringType();
                stringType.Value = sValue;
                instance.AssignmentGroup = stringType;

                sValue = SUBCATEGORY;
                stringType = new StringType();
                stringType.Value = sValue;
                instance.Area = stringType;


                sValue = PRODUCTTYPE;
                stringType = new StringType();
                stringType.Value = sValue;
                instance.Subarea = stringType;

                sValue = SERVICE;
                stringType = new StringType();
                stringType.Value = sValue;
                instance.Service = stringType;





                IncidentInstanceTypeDescription desc = new IncidentInstanceTypeDescription();
                int DescCount = arrDESCRIPTION.GetUpperBound(0);
                StringType[] stringTypes = new StringType[DescCount + 1];
                for (int ctr = 0; ctr <= DescCount; ctr++)
                {
                    sValue = arrDESCRIPTION[ctr];
                    stringType = new StringType();
                    stringType.Value = sValue;
                    stringTypes[ctr] = stringType;
                }
                IncidentInstanceTypeDescription actions = new IncidentInstanceTypeDescription();
                actions.Description = stringTypes;
                instance.Description = actions;

                IncidentInstanceTypeJournalUpdates upd = new IncidentInstanceTypeJournalUpdates();
                int DescCount1 = UPDATE.GetUpperBound(0);
                StringType[] stringTypes1 = new StringType[DescCount1 + 1];
                for (int ctr1 = 0; ctr1 <= DescCount1; ctr1++)
                {
                    sValue = UPDATE[ctr1];
                    stringType = new StringType();
                    stringType.Value = sValue;
                    stringTypes1[ctr1] = stringType;
                }
                IncidentInstanceTypeJournalUpdates act1 = new IncidentInstanceTypeJournalUpdates();
                act1.JournalUpdates = stringTypes1;
                instance.JournalUpdates = act1;


                IncidentInstanceTypeSolution upd1 = new IncidentInstanceTypeSolution();
                int DescCount11 = solution.GetUpperBound(0);
                StringType[] stringTypes11 = new StringType[DescCount11 + 1];
                for (int ctr11 = 0; ctr11 <= DescCount11; ctr11++)
                {
                    sValue = solution[ctr11];
                    stringType = new StringType();
                    stringType.Value = sValue;
                    stringTypes11[ctr11] = stringType;
                }
                IncidentInstanceTypeSolution act11 = new IncidentInstanceTypeSolution();
                act11.Solution = stringTypes11;
                instance.Solution = act11;


                return instance;
            }

            public static CreateIncidentRequest Execute(IncidentInstanceType instance,
                                                            IncidentManagement service)
            {
                IncidentModelType model = new IncidentModelType();
                IncidentKeysType keys = new IncidentKeysType();
                CreateIncidentRequest request = new CreateIncidentRequest();
                CreateIncidentResponse response2 = new CreateIncidentResponse();
                try
                {
                    model.keys = keys;
                    model.instance = instance;
                    request.model = model;
                    request.attachmentData = true;
                    request.attachmentInfo = true;
                    request.attachmentDataSpecified = true;
                    response2 = service.CreateIncident(request);
                }
                catch (Exception ex)
                {
                    return request;
                }

                return request;
            }


        }

 

 

I have also created proxy and cache but i think it does not matter. Ticket has been created but without attachment. There is no errors in SM logs.

 

Does anybody know why attachemnt has not been sent to HP SM ??

 

Thanks and Regards

Trusted Contributor
Andy_ABB
Posts: 157
Registered: ‎03-22-2012
Message 2 of 13 (1,413 Views)

Re: Attachemnts throught webservice (Createincidentrequest)

ok, i change some code and now i got this error:

 

WSE2166: The content type has an incomplete quoted parameter

 

does anyone face this problem ?

Honored Contributor
Abhijit K
Posts: 900
Registered: ‎10-14-2010
Message 3 of 13 (1,405 Views)

Re: Attachemnts throught webservice (Createincidentrequest)

Hi Andy,

 

That was pretty good code in JAVA but can you show us what XML request it is sending to HPSM. Also try to find error in sm.log ,logs has all error details for the incoming request.

 

for XML request print your final request in JAVA .

 

Hope this helps.

 

Thanks and regards,

Abhijit K

Trusted Contributor
Andy_ABB
Posts: 157
Registered: ‎03-22-2012
Message 4 of 13 (1,390 Views)

Re: Attachemnts throught webservice (Createincidentrequest)

[ Edited ]

Hi

 

It is c# code :). But does not matter which language. Im also using MTOM to send attachmrnts.

Hmm could you explain how to get XML that im sending ?

 

here is my code:

http://pastebin.com/FuwSkQAD

 

Thanks in advance

Valued Contributor
Valued Contributor
hge
Posts: 103
Registered: ‎04-07-2008
Message 5 of 13 (1,385 Views)

Re: Attachemnts throught webservice (Createincidentrequest)

Trusted Contributor
Andy_ABB
Posts: 157
Registered: ‎03-22-2012
Message 6 of 13 (1,375 Views)

Re: Attachemnts throught webservice (Createincidentrequest)

Hi

 

Im not sure what i should paste here so i will paste some output and also attach image what i see.

HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Wed, 28 Mar 2012 07:26:33 GMT
X-AspNet-Version: 4.0.30319
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 3739
Connection: Close

 

http://imageshack.us/photo/my-images/846/ssoutput.png/
Trusted Contributor
Andy_ABB
Posts: 157
Registered: ‎03-22-2012
Message 7 of 13 (1,366 Views)

Re: Attachemnts throught webservice (Createincidentrequest)

update:

 

i change part of my code:

 class myIncidentManagement : IncidentManagementWse
        {
            protected override WebResponse GetWebResponse(WebRequest request)
            {
                WebResponse response = base.GetWebResponse(request);
                if (response.Headers[HttpResponseHeader.ContentType].ToLower().StartsWith("text/xml"))
                {
                    this.RequireMtom = false;

                }
                else
                {
                    this.RequireMtom = true;
                }
                return response;
            }

        }

 

now im not getting error like the content is not valid. Ticket has been created without attachemnt with error message :

"A signal 11 was raised in native code. Client terminated. Error: Win32 Exception: 0xC0000005 (instruction 0x01000101 while reading address 0x01000101)"

 

It does not matter if i attach file or not. Anyway i can handle this error but second question why attachement is not uplaoded with ticket ? Im usign SM/7/incidentManagement.wsdl

 

Thanks and Regards

Honored Contributor
Abhijit K
Posts: 900
Registered: ‎10-14-2010
Message 8 of 13 (1,358 Views)

Re: Attachemnts throught webservice (Createincidentrequest)

Hi,

 

go through following link.

 

http://h30499.www3.hp.com/t5/HP-Service-Manager-Service/Attachment-and-Webservice/m-p/5354705#M78840

 

 

let us know further queries,

 

 

Re,

Abhijit K

Trusted Contributor
Andy_ABB
Posts: 157
Registered: ‎03-22-2012
Message 9 of 13 (1,347 Views)

Re: Attachemnts throught webservice (Createincidentrequest)

Hi i go through that link but nothing has change:

 

here is my code for attachment:

 

   byte[] buffer = null;
                FileStream fs = new FileStream("C:\\Users\\plansyn\\Desktop\\Disable_this.jpg", FileMode.Open,      FileAccess.Read, FileShare.Read);
                buffer = new byte[fs.Length];
                fs.Read(buffer, 0, (int)fs.Length);
                InMan.AttachmentType Attach = null;
                Attach = new InMan.AttachmentType();
                FileInfo file = new FileInfo("C:\\Users\\plansyn\\Desktop\\Disable_this.jpg");
                FileStream streamFile = file.OpenRead();
                Attach.href = "C:\\Users\\plansyn\\Desktop\\Disable_this.jpg";
                Attach.action = "add";
                Attach.name = "Disable_this.jpg";
                Attach.lenSpecified = true;
                Attach.len = buffer.Length;
                Attach.type = "image/jpg";
                Attach.contentType = "image/jpg";
                Attach.charset = "";
                instance.attachments = new AttachmentType[] { Attach };

 

I founs similar case using google:

http://www.sc-resources.net/threads/6754-.Net-C-Code-Calling-WebService-with-attachment

 

but he/she resolved it by changing from WSE to normal service and thats what i cant do.

 

Is there any other solution for this problem ?

 

Thanks

Trusted Contributor
Andy_ABB
Posts: 157
Registered: ‎03-22-2012
Message 10 of 13 (1,322 Views)

Re: Attachemnts throught webservice (Createincidentrequest)

Hi

 

Small update. Now tickets are created without errors. Return message is successful but still no attachment....

Trusted Contributor
Andy_ABB
Posts: 157
Registered: ‎03-22-2012
Message 11 of 13 (1,112 Views)

Re: Attachemnts throught webservice (Createincidentrequest)

Hi

 

I've enabled debbugattachmetns in sm.ini file , i see following error:

 

8016( 8084) 10/18/2012 12:12:52 RTE D Incoming XML attachment element: name=SUService.txt action=add href=C:\SUService.txt mimetype= type=5 len=3414
8016( 8084) 10/18/2012 12:12:52 RTE D Created attachment collection 2abbabc8
8016( 8084) 10/18/2012 12:12:52 RTE D Constructed temporary attachments collection 2abbabc8
8016( 8084) 10/18/2012 12:12:52 RTE D Record IM130975 of file probsummary currently has 0 attachments
8016( 8084) 10/18/2012 12:12:52 RTE D applyAttachmentUpdates() - attachment elements:
8016( 8084) 10/18/2012 12:12:52 RTE D Incoming XML attachment element: name=SUService.txt action=add href=C:\SUService.txt contentId= contentType= type=5 len=3414
8016( 8084) 10/18/2012 12:12:52 RTE D Processing add action for attachment SUService.txt with href C:\SUService.txt
8016( 8084) 10/18/2012 12:12:52 RTE D Add attachment action - looking for attachment with href C:\SUService.txt
8016( 8084) 10/18/2012 12:12:52 RTE E Error: incoming attachment add request with href C:\SUService.txt but no corresponding attachment
8016( 8084) 10/18/2012 12:12:52 RTE D New attachment collection 2abbabc8 currently has 0 entries
8016( 8084) 10/18/2012 12:12:52 RTE D putAttachments entered with collection 2abbabc8 and checksizes 1
8016( 8084) 10/18/2012 12:12:52 RTE D Destroying attachment collection 2abbabc8
8016( 8084) 10/18/2012 12:12:52 RTE D Clearing attachment collection 2abbabc8
8016( 8084) 10/18/2012 12:12:52 RTE D removing unreferenced attachments from response

 

do you know what is wrong ?

 

thanks in advance

 

Honored Contributor
Abhijit K
Posts: 900
Registered: ‎10-14-2010
Message 12 of 13 (1,100 Views)

Re: Attachemnts throught webservice (Createincidentrequest)

I guess you need to add file path as C:\\SUService.txt.
Trusted Contributor
Andy_ABB
Posts: 157
Registered: ‎03-22-2012
Message 13 of 13 (1,094 Views)

Re: Attachemnts throught webservice (Createincidentrequest)

Hi

 

Im uplaoding file using my computer -its not server directory. I tried both C:\\ and @"C:\" but no success. I preapred app to migrate some other applications to HP SM but without attachmetns we have to do it manually(more than 10k attachmetns).

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.