Error while consuming webservice

Hello All,

I have a query regarding the consuming a web services through navision I am getting two problem:-

1.When I am running this code it is giving response of 400 which is bad request.The web service is working fine it is giving result, when run through browser.

  1. The second problem is that it is giving error when i tried to take output by Commenting the status = 200 Line -

Microsoft Dynamics NAV

A DotNet variable has not been instantiated. Attempting to call MSXML.IXMLDOMNode.text in CodeUnit : OnRun

OK

The code I have mentioned below-

IF ISNULL(DotNetXmlDoc) THEN
DotNetXmlDoc := DotNetXmlDoc.DOMDocumentClass;

IF ISNULL(DotNetXmlHttp) THEN
DotNetXmlHttp := DotNetXmlHttp.XMLHTTPRequestClass;

DotNetXmlHttp.open(‘POST’,‘localhost/MyWebservice.asmx’,0,0,0);
DotNetXmlHttp.setRequestHeader(‘Host’,‘localhost’);
DotNetXmlHttp.setRequestHeader(‘Content-Type’,‘text/xml; charset=utf-8’);
DotNetXmlHttp.setRequestHeader(‘Content-Length’,‘Length’);
DotNetXmlHttp.setRequestHeader(‘SOAPAction’,'tempuri.org/mymethodname’);:wink:

DotNetXmlHttp.send(’<?xml version="1.0" encoding="utf-8"?>’
+’<soap:Envelope xmlns:xsi="www.w3.org/…/XMLSchema-instance" xmlns:xsd="www.w3.org/…/XMLSchema" xmlns:soap="schemas.xmlsoap.org/…/">’
soap:Body’+
‘’](http://tempuri.org/) +
‘’+“CustNo.”+’’+
‘’+FORMAT(Amount)+’’+
‘</soap:Body>’+
‘</soap:Envelope>’);
DotNetXmlDoc.load(DotNetXmlHttp.responseBody);
IF DotNetXmlHttp.status = 200 THEN BEGIN
DotNetXmlNodeList := DotNetXmlDoc.getElementsByTagName(‘soap:Body’);
IF ISNULL(DotNetXmlNode) THEN
DotNetXmlNode := DotNetXmlNodeList.item(0);
EVALUATE(Output,UPPERCASE(DotNetXmlNode.text(’’)));
// MESSAGE(Output);
END;

Please advise me for the same.

Thanks in advance.

Problem 1:
Your code runs on the NAV server and connects to the web service with different credentials (NetworkService or even anonymous, that depends on the .Net type you are using).
What’s needed is to provide credentials with the request.

Problem 2:
The request responds with status 400. That means that there is an error and the response body will be empty. Commenting out the check on status 200 doesn’t help you here to get access to the response. You must first solve problem 1 before you get status 200 and continue to read the response body.