Retrieve info from server request returning 500 error
Hi,
I'm creating a workflow which sends a request to another service, gets the service to do some work, then retrieves the response JSON from the service and does something with it.
I have succesfully done this for when the service returns a positive result (even though the JSON is quite complex - see a previous post).
now i'm looking at dealing with a response when the service doesn't work as expected - a failed job.
My problem is that my service seems to return a 'The remote server returned an error: (500) Internal Server Error' exception along side the JSON return ( i f i put the same uri into a browser window I get the 'failed job' JSON returned.)
This generates an exception in the workflow, which I can handle in a try/catch, but I'm struggeling to get at the response JSON (which I need) - if i use the downloadString task then the return variable is null (or is in the catch at least).
any pointers?
-
UPDATE
got it in the end.
set the exception raised by the 'try/catch activity' as a 'webexception '
this allows you to call the exception object for 'reponse', which is a webreponse object.
webreponse offers readresponsestream method, returning a memorystream object,
and you can cast this to string using:
Encoding.ASCII.GetString( memoryStream1.ToArray()) (encoding is in system.text, which you may need to import)
which returns my JSON as a string from the exception, which I can then parse in a dictionary. (see another post)
(note: for some reason I couldn't cast the response stream to a streamreader, which seems to be the usual way, but this works for me.)
0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
1 Kommentar