How to run xmlport get back data to webservie?

yukonyukon Member Posts: 361
edited 2011-01-06 in NAV Three Tier
Hi expert,

I create one xmlport at nav. And then i wann to run my xmlport and get data pass to my web. Can we get xml data from nav by using webservice? If it possible, kindly, pls guide tome.



Best Regards,
Yukon:D
Make Simple & Easy

Comments

  • kinekine Member Posts: 12,562
    Use the xmlport as parameter of the webservice. If you define it as VAR (called by reference), you can return data through it.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • eknraweknraw Member Posts: 26
    Similar to this: http://blogs.msdn.com/b/nav/archive/2009/11/06/using-dataports-with-web-services.aspx

    Alternatively, you could expose a BigText as a VAR, take the incoming request, load that into a Xml Dom object, parse, perhaps do some processing logic and then kick off an xmlport to build xml, clear your bigtext variable and then return the resultant Xml as a string.

    It'd look kinda like this:
    //  Processing logic
    
    XmlPort.SETTABLEVIEW(Rec);
    blobTemp.Blob.CREATEOUTSTREAM(OutStream);
    XmlPort.SETDESTINATION(OutStream);
    XmlPort.EXPORT;
    blobTemp.Blob.CREATEINSTREAM(InStream);
    XmlDomDoc.load(InStream);
    BigTextVar.ADDTEXT(XmlDomDoc.xml);
    

    Bill
  • yukonyukon Member Posts: 361
    Hi Kine & Bill,

    Thanks for your reply. Please me try first. Later i will let you know result.

    Best Regards,
    Yukon
    Make Simple & Easy
  • yukonyukon Member Posts: 361
    Hi eknraw,

    I follow your eg. But when i call function, i got this error. I create one codeunit and i call from nav (for testing).

    Any idea for that?

    Best Regards, :roll:
    Yukon
    Make Simple & Easy
  • yukonyukon Member Posts: 361
    Hi

    Solved ready...


    Regards,
    Yukon
    Make Simple & Easy
  • eknraweknraw Member Posts: 26
    Just in case someone is wondering, I'm guessing you were trying to use the MS XML DOM automation, which needs to be instantiated before you use it.
    CREATE(XmlDomDoc);
    
    // Or...
    
    IF ISCLEAR(XmlDomDoc) THEN
      CREATE(XmlDomDoc);
    

    yukon wrote:
    Hi

    Solved ready...


    Regards,
    Yukon
  • yukonyukon Member Posts: 361
    Hi eknraw,
    CREATE(XmlDomDoc);

    // Or...

    IF ISCLEAR(XmlDomDoc) THEN
    CREATE(XmlDomDoc);

    You right! I forget above case. :lol:

    One more thing, i can not set data to BigText. Cos of length is over 1024. :(

    Best Regards,
    Yukon
    Make Simple & Easy
  • kinekine Member Posts: 12,562
    One more thing, i can not set data to BigText. Cos of length is over 1024. :(
    And where is the problem? BigText is not limited with 1024...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • deV.chdeV.ch Member Posts: 543
    if you want to load the data in bigtext you need to read out of the stream

    bigtext.read(istream);
  • yukonyukon Member Posts: 361
    Hi deV.ch and kine,

    Thanks for your reply.
    One more thing, i can not set data to BigText. Cos of length is over 1024.
    Above part is solved ready. I replace with
    bigtext.read(istream);
    But i'm staying face with problem. ](*,)
    I'm refer this link http://mibuso.com/forum/viewtopic.php?f=32&t=29557&hilit=MemoryStream&start=15. When i run .net application i got this error "{"Data at the root level is invalid. Line 1, position 1."}". So i checked the return variable at .net. I saw data length is 3. How come? But when i export to text/xml file from nav, i can get all data.

    I'm using standard xmlport (item).

    Here is my nav code
    Name	DataType	Subtype	Length
    objOutStream	OutStream		
    objInStream	InStream		
    recTempBlob	Record	TempBlob	
    Item	Record	Item	
    
    Var	Name	DataType	Subtype	Length
    Yes	BigTextVar	BigText		
    
    Item.SETRANGE("No.",'1000');
    Item.FINDSET;
    recTempBlob.INIT;
    recTempBlob.Blob.CREATEOUTSTREAM(objOutStream);
    xmlPort.SETTABLEVIEW(Item);
    xmlPort.SETDESTINATION(objOutStream);
    xmlPort.EXPORT;
    recTempBlob.CALCFIELDS(Blob);
    recTempBlob.Blob.CREATEINSTREAM(objInStream);
    BigTextVar.READ(objInStream);
    

    .Net Code
    localhost.Web_Service_Function myInvoicesService = new WindowsApplication1.localhost.Web_Service_Function();
                myInvoicesService.UseDefaultCredentials = true;
    
                string _BigText = string.Empty;
                myInvoicesService.FnXML(ref _BigText); //Return length is 3 (data is " þ<")
    
                byte[] byteArray = new byte[_BigText.Length];
                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                byteArray = encoding.GetBytes(_BigText);
    
                System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(byteArray);
    
                DataSet ds = new DataSet();
                ds.ReadXml(memoryStream);
    

    What wrong at my sample code? Kindly, guide to me.

    Best Regards,
    Yukon
    Make Simple & Easy
  • deV.chdeV.ch Member Posts: 543
    Are you using UTF-16? I guess so, because of the data length of 3. I got this when i was using UTF-16 the file format.

    Try using UTF-8 as the xmlport format.
  • yukonyukon Member Posts: 361
    Hi deV.h

    Yes! I'm using UTF-16. Now it is ok .... :thumbsup:
    UTF-16? -> UTF-8

    Best Regards,
    Yukon
    Make Simple & Easy
Sign In or Register to comment.