Quantcast
Channel: NAV Three Tier — mibuso.com
Viewing all articles
Browse latest Browse all 10032

Error SOAP webservice

$
0
0
Hi All,

I am getting below error when running this object

A call to System.Xml.XmlDocument.InnerXml failed with this message: Root element is missing.


OBJECT Codeunit 50011 Get Currency Rate SOAP..
{
OBJECT-PROPERTIES
{
Date=10/02/15;
Time=23:45:50;
Modified=Yes;
Version List=WS;
}
PROPERTIES
{
OnRun=BEGIN
//MESSAGE('Rate = %1', GetRate('USD', 'CAD'));
SOAP_GetRate('USD', 'CAD');
SOAP_GetRate('USD', 'BGN');
END;

}
CODE
{
VAR
XMLDoc@1000000000 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument";
XMLNode@1000000013 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode";
ServiceUri@1000000001 : Text;

PROCEDURE GetRate@1000000005(fromCurrency@1000000000 : Code[20];toCurrency@1000000001 : Code[20]) : Text;
BEGIN
IF (fromCurrency = '') OR (toCurrency = '') THEN
EXIT('');
IF (fromCurrency = toCurrency) THEN
EXIT('');

XMLDoc := XMLDoc.XmlDocument;

XMLDoc.Load(STRSUBSTNO('http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=%1&ToCurrency=%2',
fromCurrency, toCurrency));

RemoveNamespace(XMLDoc, XMLDoc);

IF FindNode(XMLDoc,'//double',XMLNode) THEN
EXIT(XMLNode.InnerText)
ELSE
EXIT('');
END;

PROCEDURE SOAP_GetRate@1000000019(fromCurrency@1000000003 : Code[20];toCurrency@1000000005 : Code[20]);
VAR
HttpRequest@1000000009 : DotNet "'Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.MSXML.XMLHTTPRequestClass";
Vent@1000000001 : Dialog;
XMLDoc@1000000007 : DotNet "'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument";
XMLNode@1000000002 : DotNet "'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode";
BEGIN
IF GUIALLOWED THEN
Vent.OPEN('Sending SOAP...');

HttpRequest := HttpRequest.XMLHTTPRequestClass;
HttpRequest.open('POST', 'http://www.webservicex.net/CurrencyConvertor.asmx',FALSE, '', '');
HttpRequest.setRequestHeader('Content-Type', 'text/xml; charset=UTF-8');
HttpRequest.setRequestHeader('SOAPAction', 'http://www.webserviceX.NET/ConversionRate');

HttpRequest.send('<?xml version="1.0" encoding="utf-8"?>'+
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; '+
'xmlns:web="http://www.webserviceX.NET/">' +
'<soapenv:Header/>' +
'<soapenv:Body>'+
'<web:ConversionRate>'+
'<web:FromCurrency>'+fromCurrency+'</web:FromCurrency>'+
'<web:ToCurrency>'+toCurrency+'</web:ToCurrency>'+
'</web:ConversionRate>'+
'</soapenv:Body>'+
'</soapenv:Envelope>');

XMLDoc := XMLDoc.XmlDocument;
XMLDoc.InnerXml := HttpRequest.responseText;

IF GUIALLOWED THEN
Vent.CLOSE;

IF HttpRequest.status <> 200 THEN
MESSAGE('Http Error ' + ' ' + FORMAT(HttpRequest.status) + ': ' + HttpRequest.statusText)
ELSE BEGIN
RemoveNamespace(XMLDoc, XMLDoc);
IF FindNode(XMLDoc, '//Envelope/Body/ConversionRateResponse/ConversionRateResult',XMLNode) THEN
MESSAGE('Currency rate from %1 to %2 = %3', fromCurrency, toCurrency, XMLNode.InnerText);
END;
END;

PROCEDURE RemoveNamespace@1000000004(XMLDocIn@1000000000 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument";VAR XMLDocOut@1000000001 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument");
VAR
XMLStyleSheet@1000000005 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument";
XslTransform@1000000004 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.Xsl.XslTransform";
writer@1000000003 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.StringWriter";
nullXsltArgumentList@1000000002 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.Xsl.XsltArgumentList";
BEGIN
// before this function your tag looks like this: <namespace:tagname>sample text</tagname>
// after this function your tag looks like this: <tagname>sample text</tagname>
// additionally all namespace references in the head are removed.
XslTransform := XslTransform.XslTransform;
XMLStyleSheet := XMLStyleSheet.XmlDocument;
XMLStyleSheet.InnerXml(
'<?xml version="1.0" encoding="UTF-8"?>' +
'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">' +
'<xsl:output method="xml" encoding="UTF-8" />' +
'<xsl:template match="/">' +
'<xsl:copy>' +
'<xsl:apply-templates />' +
'</xsl:copy>' +
'</xsl:template>' +
'<xsl:template match="*">' +
'<xsl:element name="{local-name()}">' +
'<xsl:apply-templates select="@* | node()" />' +
'</xsl:element>' +
'</xsl:template>' +
'<xsl:template match="@*&quot;;>' +
'<xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>' +
'</xsl:template>' +
'<xsl:template match="text() | processing-instruction() | comment()">' +
'<xsl:copy />' +
'</xsl:template>' +
'</xsl:stylesheet>'
);

XslTransform.Load(XMLStyleSheet);
writer := writer.StringWriter();
XslTransform.Transform(XMLDocIn, nullXsltArgumentList, writer);
XMLDocOut := XMLDocOut.XmlDocument;
XMLDocOut.InnerXml(writer.ToString());
END;

PROCEDURE FindNode@3(XMLRootNode@1000 : DotNet "'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode";NodePath@1001 : Text[250];VAR FoundXMLNode@1002 : DotNet "'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode") : Boolean;
BEGIN
FoundXMLNode := XMLRootNode.SelectSingleNode(NodePath);

IF ISNULL(FoundXMLNode) THEN
EXIT(FALSE)
ELSE
EXIT(TRUE);
END;

LOCAL PROCEDURE Authenticate@40(ServiceInstance@1001 : DotNet "'System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.Web.Services.Protocols.SoapHttpClientProtocol");
VAR
WebServicesSetup@1003 : Record 123456701;
Client@1000 : DotNet "'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.WebRequest";
Credential@1002 : DotNet "'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.NetworkCredential";
BEGIN
WITH WebServicesSetup DO BEGIN
IF FINDFIRST THEN
ServiceInstance.Credentials := Credential.NetworkCredential("User name",Password)
ELSE
ServiceInstance.UseDefaultCredentials := TRUE;
END;
END;

BEGIN
END.
}
}

Viewing all articles
Browse latest Browse all 10032

Trending Articles