Options

NAV 2009 XMLPort with Web Services (VB.net example)

jwilderjwilder Member Posts: 263
edited 2009-05-11 in NAV Three Tier
I am looking for a basic example of using an xmlport with web services. I have followed Freddy's Blog which does this with a Vista Gadget + J Script. So I am just looking for the simplest example of the vb.net code, I already have a codeunit + Functions + xmlport setup similar to the one in Freddy's Blog - Vista Gadget - My "Stuff". For an easy example I am just looking to return the results of the xmlport to a variable.

Comments

  • Options
    freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    Sorry that I don't speak VB - but a simple C# sample can be found here (4 lines c# towards the end)

    http://www.mibuso.com/forum/viewtopic.php?f=32&t=29557

    Hopefully that helps
    Freddy Kristiansen
    Group Program Manager, Client
    Microsoft Dynamics NAV
    http://blogs.msdn.com/freddyk

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • Options
    jwilderjwilder Member Posts: 263
    Freddy thanks for your so far, I am almost there. I need a tiny bit more help with the visual studio code:
    WSTest1.MyXMLCusts myXMLcusts = new WSTest1.MyXMLCusts();
    test.GetXMLPort(ref myXMLcusts);
    foreach (WSTest1.MyXMLCust myXMLcust in myXMLcusts.MyXMLCust)

    Can you add the rest of the code for the initial connection? I think the test variable is the web service
  • Options
    jwilderjwilder Member Posts: 263
    edited 2009-03-06
    I got it! Using Freddy's example in this link ( http://www.mibuso.com/forum/viewtopic.php?f=32&t=29557 ) for the NAV Codeunit + XMLPort here is the VB.net code in Visual Studio:
    Dim Test As New NAVWebservice.NAVCodeunit
    Test.UseDefaultCredentials = True
    Test.Url = "http://swk-lab2:7047/DynamicsNAV/WS/SWKTestU5/Codeunit/NAVCodeunit"
    
    Dim myXMLCusts As New NAVWebservice.MyXMLCustomers
    Test.GetXMLPort(myXMLCusts)
    For Each myXMLCust In myXMLCusts.MyXMLCustomer
        MsgBox(myXMLCust.No & " " & myXMLCust.Name)
    Next
    
    Thanks Freddy!
  • Options
    freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    and thanks for putting up the vb.net sample =D>
    Freddy Kristiansen
    Group Program Manager, Client
    Microsoft Dynamics NAV
    http://blogs.msdn.com/freddyk

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • Options
    MBrodie1979MBrodie1979 Member Posts: 21
    Hello everyone.

    I was looking at your VB Code and I was wondering what I would need to change to be able to pass an XML file as a parameter to a function that had a data type of type file as opposed to XML Port?

    I have a function called NewInvoice(VAR InvoiceXMLDoc : File). I want NewInvoice to be accessible via web services but I don't know much about VB and I need to test my NAV function works when called from another programming language.

    I have tried but I am battling to understand the VB syntax and I cannot try any other language as I only have VB on my laptop (from Excel).

    ANy help would be greatly apperciated. :D

    ](*,)
  • Options
    jwilderjwilder Member Posts: 263
    Very interesting, I haven't tried passing back a file as a var parameter, but I have done this in a different way. Instead of using a File variable use BigText. I am workign on an example of this but basically do this:

    1) Create an xmlport (make sure property Encoding is set to UTF-8)

    2) Create a funcion in a codeunit that you will publish as a web service. Required Parameter is
    Bigtext (make sure var is checked)

    3) You'll need some Navision code like this:
    TempBlob.Blob.CREATEOUTSTREAM(StreamOut)
    YourXMLPort.SETDESTINATION(StreamOut);
    YourXMLPort.EXPORT; //This fills the tempblob with your xmlfile
    TempBlob.MODIFY;
    TempBlob.Blob.CREATEINSTREAM(StreamIn);
    BigText.READ(StreamIn); //This copys the xmlfile stored in the blob into the bigtext variable

    Tempblob datatype record 99008535 temporary = yes
    streamOut datatype Outstream
    YourXMLPort datatype XMLPort ####?
    StreamIn datatype InStream
    BigText datatype BigText

    Tell me if table 99008535 does not exist in your database. The trick behind this whole thing is to fill the BigText variable with whatever you want (Xml,csv file etc...) and pass it to your vb.net call.
    The vb.net call just needs to pass a blank string into the bigtext parameter. It the end this string will contain your xmlfile.
  • Options
    @simon@simon Member Posts: 17
    Rather than looping through each element of the array, you can do the following to load it into a dataset (example is in c#):
    public void BindNAVArray(NAVService.ARRAYOBJECT _ArrayObject)
        {
            DataSet ds = new DataSet();
    
            XmlSerializer xmlSerializer = new XmlSerializer(_ArrayObject.GetType());
            StringWriter stringWriter = new StringWriter();
    
            xmlSerializer.Serialize(stringWriter, _ArrayObject);
    
            StringReader stringReader = new StringReader(stringWriter.ToString());
    
            ds.ReadXml(stringReader);
    
        }
    
  • Options
    jwilderjwilder Member Posts: 263
    I've been looking for something like that. Thanks, I will definitely try this out!
Sign In or Register to comment.