using web services to retrieve attachments to change tickets (951 Views)
Reply
Valued Contributor
lss123
Posts: 85
Registered: ‎06-29-2011
Message 1 of 12 (951 Views)
Accepted Solution

using web services to retrieve attachments to change tickets

I'm trying to use web services to retrieve attachments to change tickets.  I do not appear to be succeeding.  I'm writing code in .NET that makes use of web services.  I can retrieve one or a list of changes without issue.  I am setting the attachmentData and attachmentInfo fields to "true" in my request. 

 

When the response is returned, the attachment field is null.

 

Is there anything else I have to do?  Thanks.  Here is a small code snippet:

 

changeRequest.attachmentData = true;
changeRequest.attachmentInfo = true;
changeRequest.ignoreEmptyElements = true;

 

Please use plain text.
Trusted Contributor
Andy_ABB
Posts: 155
Registered: ‎03-22-2012
Message 2 of 12 (927 Views)

Re: using web services to retrieve attachments to change tickets

I've wasted a lot of time to upload/download attachment using .net and WS. After that i asked HP support if its possible then they said we have a bug in HP SM and its not possible.

 

BR

Please use plain text.
Valued Contributor
lss123
Posts: 85
Registered: ‎06-29-2011
Message 3 of 12 (919 Views)

Re: using web services to retrieve attachments to change tickets

Thanks for your reply.  I swear I saw threads where people said this was possible, but apparently it's not as possible as I thought.  Here's what HP support has told me so far:

 

I believe those methods (attachmentData, etc) are for sending an attachment to SM, not for pulling from SM. I am in the process of checking for you, but I do not believe that OOB SM supports returning attachments on demand due to binary data handling and web service security risks. Some tailoring work in SM is necessary (you will need to write SM script libraries) per my last update to handle the wsdl request, and then the binary data retrieval from SM's SYSATTACHMENT table (eg; native getAttachment method) and insert it into the SOAP response packet.

 

This is typically done in JS, eg;

  var f = new SCFile( 'cm3r' );

  var rc = f.doSelect( 'number = "C10001"' );

  var attachmentObj = f.getAttachments();

  for ( var attachment in attachmentObj )

  {

    print("Attachment Name:  "+ attachmentObj[ attachment ].name );

    print("Attachment Value:  "+ attachmentObj[ attachment ].stringValue );

    print("Attachment Value Length:  "+ attachmentObj[ attachment ].stringValue.length );

    print("Attachment HREF:  "+ attachmentObj[ attachment ].href );

    print("Attachment Type:  "+ attachmentObj[ attachment ].type);

    str+= attachmentObj[ attachment ].stringValue ;

  }

  print("String Length:  "+str.length);

  //etc

 

I am not able to locate a complete script example of how this is attached to the returning web service response, but per my last update, I believe Professional Services have worked on projects like this in the past. They will need to be contacted for more detailed examples.

Please use plain text.
Valued Contributor
lss123
Posts: 85
Registered: ‎06-29-2011
Message 4 of 12 (916 Views)

Re: using web services to retrieve attachments to change tickets

In this thread, the poster seems to be retrieving attachment data just using web services (http://h30499.www3.hp.com/t5/HP-Service-Manager-Service/Retrieve-MIME-attachment/m-p/5270432/highlig...). 

 

In my .NET code, I'm doing what he's doing.  Has something changed?  Did this functionality break?

Please use plain text.
Valued Contributor
lss123
Posts: 85
Registered: ‎06-29-2011
Message 5 of 12 (910 Views)

Re: using web services to retrieve attachments to change tickets

I made progress today in that I can now get HPSM to return file data.  The code below is what I needed:

 

changeRequest.attachmentData = true;
changeRequest.attachmentInfo = true;
changeRequest.attachmentDataSpecified = true;
changeRequest.attachmentInfoSpecified = true;

 

However, my .NET client throws an error when receiving the response.  The error is long, but it starts like this:

"Client found response content type of 'multipart/related; type="text/xml"; boundary="----=_Part_50_6238894.1371488591938" ', but expected 'text/xml'."

I am continuing to research this now. 

 

If anyone knows how to resolve the latest error, I'd really appreciate it.

Please use plain text.
Occasional Advisor
MaxP
Posts: 8
Registered: ‎07-13-2011
Message 6 of 12 (843 Views)

Re: using web services to retrieve attachments to change tickets

"However, my .NET client throws an error when receiving the response. The error is long, but it starts like this:

"Client found response content type of 'multipart/related; type="text/xml"; boundary"

 

Hi , I have same error. Some people saw what cause of that is different between request and response objects(see post by Carlos http://social.msdn.microsoft.com/Forums/vstudio/en-US/480f1bc4-1fc4-40e9-a2ed-efcf3009d6ef/can-you-o.... )

 

Is You found a solution for working with attachments?

Max

Please use plain text.
Valued Contributor
lss123
Posts: 85
Registered: ‎06-29-2011
Message 7 of 12 (841 Views)

Re: using web services to retrieve attachments to change tickets

Yes, I did.  I added messageEncloding="Mtom" to the web.config file as an attribute of the binding and that resolved this error.  I did this a while ago so I don't know if I had to do anything else, but I definitely am retrieving attachments through web services, so it's possible.  If you need more help just update this thread.

Please use plain text.
Occasional Advisor
MaxP
Posts: 8
Registered: ‎07-13-2011
Message 8 of 12 (823 Views)

Re: using web services to retrieve attachments to change tickets

Good news :)

is web.config on client-side ? I put on my app.config :

<bindings><wsHttpBinding>

<binding messageEncoding="Mtom"/>

</wsHttpBinding></bindings>

 

but the error still reside.

Is you use a WEB-reference to "..sc62server/PWS/.." in your .net -project or use ServiceHost variable ?

 

Please use plain text.
Valued Contributor
lss123
Posts: 85
Registered: ‎06-29-2011
Message 9 of 12 (820 Views)

Re: using web services to retrieve attachments to change tickets

[ Edited ]

I don't know if anything in app.config will help; that's not what I did.  Web.config is the configuration file in the root of any .NET project; when you deploy the project to IIS, web.config goes with it (so it's on the server side).  When you add a Service Reference (steps outlined below), it'll add the configurations for it in web.config.

 

To set up the WSDL to HPSM, I used a Service Reference:

 

a) I right-clicked on Service References in the Solution Explorer

b) I chose "Add Service Reference"

c) I put in the address and the namespace and clicked the OK button.

 

I used this WSDL:  http://<hpsmhost>:<portnumber>/SM/7/ws/<WSDL name>.  I think this is important - you need to use the Service Reference, and you need to use /SM/7 - at least, I remember choosing these things specifically when I did this.

 

Do the steps above and see how far you get.  If you get an error or get stuck, update the thread.

Please use plain text.
Frequent Advisor
Islam Nofal
Posts: 82
Registered: ‎05-05-2010
Message 10 of 12 (332 Views)

Re: using web services to retrieve attachments to change tickets

Hello Experts,

I'm facing the same issue.
I'm consuming the web service using add web reference, not as a service reference.

so I'm not able to configure the Encoding parameters, I tried to consume the web service as service reference, but I'm stuck in the authentication steps.

I'll appreciate if you can tell me how to authenticate the consuming of the service in order to try the encoding part.

Thanks,
Islam Nofal
Please use plain text.
Valued Contributor
lss123
Posts: 85
Registered: ‎06-29-2011
Message 11 of 12 (315 Views)

Re: using web services to retrieve attachments to change tickets

When I create the HPSM web service client object, part of that object are credentials.  I can show you the .NET code I used to add the credentials, and that's all I had to do as far as authentication.

 

myHpsmWebServiceClient ws = new myHpsmWebServiceClient();
ws.ClientCredentials.UserName.UserName = username;
ws.ClientCredentials.UserName.Password = password;

 

 

That's i!

Please use plain text.
Frequent Advisor
Islam Nofal
Posts: 82
Registered: ‎05-05-2010
Message 12 of 12 (307 Views)

Re: using web services to retrieve attachments to change tickets

Thanks alot,

 

This solved the authentication problem and the encoding solved the attachment problem.

 

Regards,

Islam Nofal

Please use plain text.
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