XML API Integration

navuser1navuser1 Member Posts: 1,329
Dear All,

How do I sent a xml file to a webservice in NAV 2016 Platform?
Kindly reply.

Thanks,
Navuser1
Now or Never

Best Answer

  • navuser1navuser1 Member Posts: 1,329
    Answer ✓
    Done!
    Successfully I'm able to send my created xml file into the Web Service. The following code helps me in this requirement...
    HttpWebRequestMgt.Initialize('URL');
    HttpWebRequestMgt.DisableUI;
    HttpWebRequestMgt.SetMethod('POST');
    HttpWebRequestMgt.AddBody(FilePath); //Xml file path
    TempBlob.INIT;
    TempBlob.Blob.CREATEINSTREAM(Instr);
    IF HttpWebRequestMgt.GetResponse(Instr,HttpStatusCode,ResponseHeaders) THEN BEGIN
      MESSAGE('HttpStatusCode : '+FORMAT(TempBlob.ReadAsText('',TEXTENCODING::UTF8)));
      //Save response....
      XMLDocumentTest :=XMLDocumentTest.XmlDocument;
      XMLDocumentTest.Load(Instr);
      XMLDocumentTest.Save('C:\xml1.xml');
    
    END;
    
    Name DataType Subtype
    HttpWebRequestMgt Codeunit Http Web Request Mgt.
    TempBlob Record TempBlob
    Instr InStream
    XMLDocumentTest DotNet System.Xml.XmlDocument.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    HttpStatusCode DotNet System.Net.HttpStatusCode.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    ResponseHeaders DotNet System.Collections.Specialized.NameValueCollection.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    basfnetx553n.png
    Now or Never

Answers

  • KlappspatenKlappspaten Member Posts: 22
    edited 2019-10-09
    IMHO it depends on what the counterpart of the webservice is. I assume that you have some sort of .NET application consuming the webservice, like an ASP.NET website or a simple C# program.
    If this is the case, you can write your xml file into a bigtext and send this via webservice.
    Some thing come in handy here:
    1. bigtexts can store binary data (including null terminals) up to any size.
    2. strings in .NET can have any size and any content
  • navuser1navuser1 Member Posts: 1,329
    Thanks for the reply.
    I have created the XML file & stored it in a physical Path & now I want to send the whole file into a Web Service. Is it possible without considering the bigtext ??
    Now or Never
  • KlappspatenKlappspaten Member Posts: 22
    Yo can use XMLPorts with webservices. But I have never used these together.
  • navuser1navuser1 Member Posts: 1,329
    Answer ✓
    Done!
    Successfully I'm able to send my created xml file into the Web Service. The following code helps me in this requirement...
    HttpWebRequestMgt.Initialize('URL');
    HttpWebRequestMgt.DisableUI;
    HttpWebRequestMgt.SetMethod('POST');
    HttpWebRequestMgt.AddBody(FilePath); //Xml file path
    TempBlob.INIT;
    TempBlob.Blob.CREATEINSTREAM(Instr);
    IF HttpWebRequestMgt.GetResponse(Instr,HttpStatusCode,ResponseHeaders) THEN BEGIN
      MESSAGE('HttpStatusCode : '+FORMAT(TempBlob.ReadAsText('',TEXTENCODING::UTF8)));
      //Save response....
      XMLDocumentTest :=XMLDocumentTest.XmlDocument;
      XMLDocumentTest.Load(Instr);
      XMLDocumentTest.Save('C:\xml1.xml');
    
    END;
    
    Name DataType Subtype
    HttpWebRequestMgt Codeunit Http Web Request Mgt.
    TempBlob Record TempBlob
    Instr InStream
    XMLDocumentTest DotNet System.Xml.XmlDocument.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    HttpStatusCode DotNet System.Net.HttpStatusCode.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    ResponseHeaders DotNet System.Collections.Specialized.NameValueCollection.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    basfnetx553n.png
    Now or Never
Sign In or Register to comment.