Options

DotNet for WebRequest.

VarikVarik Member Posts: 13
edited 2015-03-18 in NAV Three Tier
Hi All.

I use DotNet Object for webrequest. When do last line I have error.
A call to System.Net.HttpWebRequest.GetResponse failed with this message: Object reference not set to an instance of an object.

Where I make mistake?
lgRequest := lgRequest.HttpWebRequest;
lgRequest.Create('http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=CAD');

lgResponse := lgResponse.HttpWebResponse;
lgResponse := lgRequest.GetResponse();

Declared Var:
lgRequest	DotNet	System.Net.HttpWebRequest.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
lgResponse	DotNet	System.Net.HttpWebResponse.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

Comments

  • Options
    ftorneroftornero Member Posts: 523
    In this case you don't need to use HttpWebRequest

    Try this
    OBJECT Codeunit 50000 Get Currency Rate
    {
      OBJECT-PROPERTIES
      {
        Date=06/02/15;
        Time=21:19:17;
        Modified=Yes;
        Version List=WS;
      }
      PROPERTIES
      {
        OnRun=BEGIN
                GetRate;
              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";
    
        PROCEDURE GetRate@1000000005();
        BEGIN
          XMLDoc := XMLDoc.XmlDocument;
    
          XMLDoc.Load('http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=CAD');
    
          RemoveNamespace(XMLDoc, XMLDoc);
    
          IF FindNode(XMLDoc,'//double',XMLNode) THEN
             MESSAGE('Rate = %1', XMLNode.InnerText);
        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="@*">' +
          '<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;
    
        BEGIN
        END.
      }
    }
    
  • Options
    VarikVarik Member Posts: 13
    ftornero wrote:
    In this case you don't need to use HttpWebRequest

    Try this
    OBJECT Codeunit 50000 Get Currency Rate
    
    

    Thanks a lot. This solution help me for this task.

    But, if it's posible, I would like to know what a mistake I made in my code?
  • Options
    mandykmandyk Member Posts: 57
    Hi Varik,
    If I am not mistaken, you should call method "send" first before expecting a web response.
    From the code you are writing is just create an instance dot net object and it certainly does not perform web request immediately.
    Another point you should check if response is ready. Internet response should not be faster than local CPU to execute the command instruction. So there are few things you can improve first! Good luck!
  • Options
    ftorneroftornero Member Posts: 523
    Varik wrote:
    ftornero wrote:
    In this case you don't need to use HttpWebRequest

    Try this
    OBJECT Codeunit 50000 Get Currency Rate
    
    

    Thanks a lot. This solution help me for this task.

    But, if it's posible, I would like to know what a mistake I made in my code?

    You need to change this line
    lgRequest.Create('http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=CAD');
    

    for this one
    lgRequest := lgRequest.Create('http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=CAD');
    
  • Options
    VarikVarik Member Posts: 13
    ftornero wrote:
    In this case you don't need to use HttpWebRequest

    Try this
    OBJECT Codeunit 50000 Get Currency Rate
    {
      OBJECT-PROPERTIES
      {
        Date=06/02/15;
        Time=21:19:17;
        Modified=Yes;
        Version List=WS;
      }
      PROPERTIES
      {
        OnRun=BEGIN
                GetRate;
              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";
    
        PROCEDURE GetRate@1000000005();
        BEGIN
          XMLDoc := XMLDoc.XmlDocument;
    
          XMLDoc.Load('http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=BGN');
    
          RemoveNamespace(XMLDoc, XMLDoc);
    
          IF FindNode(XMLDoc,'//double',XMLNode) THEN
             MESSAGE('Rate = %1', XMLNode.InnerText);
        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="@*">' +
          '<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;
    
        BEGIN
        END.
      }
    }
    
    Result web-request:
    http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=BGN
    
    Is:
    System.ArgumentException: Cannot convert BGN to Currency.
    Parameter name: type ---> System.ArgumentException: Requested value &#39;BGN&#39; was not found.
       at System.Enum.EnumResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument)
       at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult)
       at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
       at System.Web.Services.Protocols.ScalarFormatter.FromString(String value, Type type)
       --- End of inner exception stack trace ---
       at System.Web.Services.Protocols.ScalarFormatter.FromString(String value, Type type)
       at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)
       at System.Web.Services.Protocols.UrlParameterReader.Read(HttpRequest request)
       at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
       at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
    
    If I use your code for this currency pair USD and BNG automatically, in string
    XMLDoc.Load('http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=BGN');
    
    Nav give me next error message:
    Microsoft Dynamics NAV. A call to System.Xml.XmlDocument.Load failed with this message: The remote server returned an error: (500) Internal Server Error.
    Because this WebService can't return results for this currency pair.
    How I can automatically handle this error? Because XMLDoc.Load didn't return any results of his work.
  • Options
    ftorneroftornero Member Posts: 523
    To handle the error you can use a SOAP call like this:
    OBJECT Codeunit 50010 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="@*">' +
          '<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.
      }
    }
    
  • Options
    DRBDRB Member Posts: 105
    Hi Fternero,
    I am getting following error in your last piece of code:

    A call to System.Xml.XmlDocument.InnerXml failed with this message: '>' is an unexpected token. The expected token is '"' or '''. Line 1, position 62.

    Does this mean the desired request format at the server has changed?

    In addition to above I am getting some other errors in similar code for consuming NAV webservice which is called from another NAV database:

    1. 500 Internal Error
    2. This message is for C/AL programmers: A call to System.Net.HttpWebRequest.GetResponse failed with this message: The remote server returned an error: (411) Length Required.
    3. A call to MSXML.XMLHTTPRequestClass.send failed with this message.Value does not fall within the expected range

    Another issue is you are using

    MSXML.XMLHTTPRequestClass.'Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

    which is not available in one of my server and could not find its installed setup also. Is there any good replacement of above DotNet component? Is there any sample code for Adding SOAPEnvelope and consuming NAV webservice using DotNet components (not automation variables) for NAV2013 & NAV 2015?

    Thanks in advance.
    -Dhan Raj Bansal
    Linkedin Profile: http://in.linkedin.com/in/dhanrajbansal
  • Options
    AlexRichterAlexRichter Member Posts: 4
    edited 2015-11-13
    Hi everyone,

    im trying to use the SOAP GetRate Function in NAV2015 an getting the following Message:

    System.Xml.XmlDocument.InnerXml : Root element is missing.

    The Debugger stops here:
    XMLDoc.InnerXml := HttpRequest.responseText;

    EDIT:
    I was a bit to fast.
    issue was solved quite easy: I repaced the &lt and &gt characters with <> and it works.
    Thanks!

    Here the complete Code:
    
    
    LOCAL HandleResponse(fromCurrency : Code[20];toCurrency : Code[20])
    IF GUIALLOWED THEN
      Vent.OPEN('Sending SOAP...');
    
    HttpRequest := HttpRequest.XMLHTTPRequestClass;
    HttpRequest.open('POST', 'http://www.webservicex.net/CurrencyConvertor.asmx',FALSE, '', '');
    
    //HttpRequest.open('POST', 'http://requestb.in/139mgp71',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"?>'+
                 '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'+
                   '<soap:Body>'+
                     '<ConversionRate xmlns="http://www.webserviceX.NET/">'+
                        '<FromCurrency>'+fromCurrency+'</FromCurrency>'+
                        '<ToCurrency>'+toCurrency+'</ToCurrency>'+
                     '</ConversionRate>'+
                   '</soap:Body>'+
                 '</soap: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;
    
    LOCAL RemoveNamespace(XMLDocIn : DotNet "System.Xml.XmlDocument";XMLDocOut : DotNet "System.Xml.XmlDocument")
    // 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="@* " >' +
                           '<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());
    

Sign In or Register to comment.