Consuming REST webservice using NAV

DRBDRB Member Posts: 105
edited 2013-09-24 in NAV Three Tier
Hi,
I am trying to consume REST webservice in NAV, but it is giving error:

"Error 405: Method not allowed".

Which means either readystate or status is not as expected.

Please help me in resolving this issue.

Following is the code used:

OBJECT Codeunit 90002 WebService Connection
{
OBJECT-PROPERTIES
{
Date=11-01-12;
Time=15:05:21;
Modified=Yes;
Version List=;
}
PROPERTIES
{
OnRun=BEGIN
CREATE(XmlIn);
CREATE(XmlOut);
// Populating XmlIn document for test purposes
LoadTestXml();
// Invoke method
Send();
// Save result to disc
XmlOut.save('C:\Temp\XML\response.xml');
END;
}
CODE
{
VAR
XmlIn@1000000004 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v6.0'.DOMDocument";
XmlOut@1000000003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v6.0'.DOMDocument";
locautXmlHttp@1160870000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A0A-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.XMLHTTP60";
PROCEDURE Send@1000000004();
BEGIN
// Communication
CREATE(locautXmlHttp);
locautXmlHttp.open('POST','http://localhost:56063/RESTservice.ashx',0);
locautXmlHttp.setRequestHeader('Content-type','text/xml; charset=utf-8');
locautXmlHttp.setRequestHeader('KeepAlive','false');
locautXmlHttp.setRequestHeader('Timeout','5000');
// Send request
locautXmlHttp.send(XmlIn);
// Get response
XmlOut := locautXmlHttp.responseXML;
XmlOut.async := TRUE;
// Show result
MESSAGE(XmlOut.xml);
END;
PROCEDURE LoadTestXml@1160870000();
BEGIN
XmlIn.loadXML(
'<xmltest>' +
'<test>' +
'This document can contain anything. But must not contain xml decleration.' +
'</test>' +
'</xmltest>');
END;
BEGIN
{
Shows how to connect to a REST Web Service
}
END.
}
}

Thanks to http://navcode.blogspot.in/2012/01/conn ... 9419528789 for the code
-Dhan Raj Bansal
Linkedin Profile: http://in.linkedin.com/in/dhanrajbansal
Sign In or Register to comment.