I have in AX2012 method like this:
public void SendRequest()
{
CLRObject clrObj;
System.Net.HttpWebRequest webReq;
System.Net.ServicePoint servicePt;
System.Net.WebHeaderCollection headers;
System.Text.Encoding utf8Enc;
System.IO.Stream stream;
System.Byte[] bodyBytes;
System.Net.WebException ex;
System.Net.HttpWebResponse webExRes;
System.Net.HttpWebResponse webRes;
System.IO.StreamReader streamReader;
System.Net.HttpStatusCode HttpStatusCodeTmp;
System.IO.BinaryReader binaryReader;
System.Int32 countOfBytes;
System.Byte[] responseBinaryBytes;
System.IO.MemoryStream memStream;
str strAuth;
boolean debug = true;
boolean CommitRequest = true;
;
try
{
new InteropPermission(InteropKind::ClrInterop).assert();
clrObj = System.Net.WebRequest::Create(requestPath);
webReq = clrObj;
servicePt = webReq.get_ServicePoint();
servicePt.set_Expect100Continue(false);
webReq.set_Method(requestMethod);
webReq.set_KeepAlive(true);
webReq.set_AutomaticDecompression(System.Net.DecompressionMethods::GZip);
headers = new System.Net.WebHeaderCollection();
headers.Add("Auth", strAuth);
headers.Add("Timestamp", timestamp);
webReq.set_Headers(headers);
utf8enc = System.Text.Encoding::get_UTF8();
stream = webReq.GetRequestStream();
bodyBytes = utf8enc.GetBytes(requestBody);
stream.Write(bodyBytes, 0, bodyBytes.get_Length());
webReq.set_ContentType("application/json");
webReq.set_Accept("*/*");
try
{
webRes = webReq.GetResponse();
info(strfmt("I'm here after GetResponse"));
}
catch (Exception::CLRError)
{
error (strFmt("Exception::CLRError"0));
}
catch
{
error (strFmt("Otjer error"));
}
CodeAccessPermission::revertAssert();
}
catch(Exception::CLRError)
{
throw error(AifUtil::getClrErrorMessage());
}
info(strfmt("Method end"));
}
If I send POST - all is OK; (error code 201, 403) -)
If I send PUT and receive code 204 - all is OK
If I send PUT and receive code 422 (Unprocessable Entity (WebDAV) (RFC 4918)) AX stops and I don't see message "I'm here after GetResponse"
What is wrong ??? Why I can't use try..catch .. in error 422 ? AX breaks all code after webReq.GetResponse ! What can I do ?