C/AL, NAV2016, HttpWebRequest, processing fault response

northyen
Member Posts: 14
How you do get the fault response InStream (or for that sake, file) from the HttpWebRequest, without modifying C1297?
NAV is posting to a webservice that returns status 422, which means that there are errors in the data supplied. I'm trying to find a way to get this information for further processing. Right now I just get the status "422 Unprocessable Entity", but not the response body.
It seems that SetTraceLogEnabled actually does this, but I'm unable to get the file name, and I'd prefer a stream anyhow.
NAV is posting to a webservice that returns status 422, which means that there are errors in the data supplied. I'm trying to find a way to get this information for further processing. Right now I just get the status "422 Unprocessable Entity", but not the response body.
It seems that SetTraceLogEnabled actually does this, but I'm unable to get the file name, and I'd prefer a stream anyhow.
0
Answers
-
Codeunit 1299 has a nice function for inspiration: "GetWebResponseError". However, personally, I didn't find it fully suitable for my needs, so I used parts of it and made my own handling that looks something like this:
IF NOT TryAPIRequest(HttpWebRequest_L,HttpWebResponse_L) THEN BEGIN //TryAPIRequest is a simplified version of COD1297's "GetWebResponse" DotNetExceptionHandler.Collect; IF NOT DotNetExceptionHandler.CastToType(WebException_L,GETDOTNETTYPE(WebException)) THEN DotNetExceptionHandler.Rethrow; IF ISNULL(WebException.Response) THEN DotNetExceptionHandler.Rethrow; HttpWebResponse := WebException.Response; ResponseStream := HttpWebResponse.GetResponseStream();
DotNetExceptionHandler: COD1291
Find other types in COD1299.GetWebResponseError0 -
I found the solution late last night actually, that fits my needs. I got completely confused about the "WebException" part as it seem that the DotNet exceptions actually lives in some kind of super-global scope.
I.e. I don't have to think about scopes, parameters, references or anything like that. Confusing!IF NOT HttpWebRequestMgt.GetResponse(Instr,HttpStatusCode,ResponseHeaders) THEN BEGIN FaultResponse := WebRequestHelper.GetWebResponseError(WebException, ServiceURL); IF NOT ISNULL(WebException.Response) THEN BEGIN Instr := WebException.Response.GetResponseStream; StreamToLog(Instr,"Function" + ' Response'); END; END;
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions