Hello,
I would like consume a webservice REST in AX2009 to track the shipment of our orders.
For this I used this example : Consuming REST APIs in Dynamics AX 2012 (folio3.com)
I modified for my case like this :
static void Job37(Args _args)
{
System.Net.HttpWebRequest webReq;
System.Net.HttpWebResponse webRes;
CLRObject clrObj;
System.IO.Stream stream;
System.IO.StreamReader streamRead;
System.IO.StreamWriter streamWrite;
System.Net.ServicePoint servicePt;
System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
;
//This line gives the user control to run unmanaged and managed code
new InteropPermission(InteropKind::ClrInterop).assert();
// Create Object for adding headers
headers = new System.Net.WebHeaderCollection();
clrObj = System.Net.WebRequest::Create("https://api.dachser.com/rest/v2/shipmenthistory?tracking-number=4619790347927552&customer-id=231993665126400");
webReq = clrObj;
//Set Method Type
webReq.set_Method("GET");
webReq.set_KeepAlive(true);
// Set Content type
webReq.set_ContentType("application/xml");
// Add Authorization code
//headers.Add("Authorization", "sdfgvczzxcbtyfrvb");
headers.Add("X-IBM-Client-Id", "clientId");
headers.Add("Accept-Language", "en");
headers.Add("accept", "application/json");
//Add header to request
webReq.set_Headers(headers);
//Get Service Point
servicePt = webReq.get_ServicePoint();
servicePt.set_Expect100Continue(false);
//Gets the response object
webRes = webReq.GetResponse();
//Get Stream
stream = webRes.GetResponseStream();
streamRead = new System.IO.StreamReader(stream);
stream.Close();
webRes.Close();
}
But the code exits on “webReq.set_Headers(headers);” line.
I don’t know why. Please could you help me ?
Thanks a lot.