NAV 2013 WebService inspiration needed

RudolfRudolf Member Posts: 10
edited 2012-10-25 in NAV Three Tier
Hi,

I am looking for some inspiration to creating NAV WebServices, as the documentation and examples I have been able to find doesn’t contain, what I am looking for.

I am working on a new solution where all business logic shall be performed inside NAV and with a .NET based frontend (UI).

I need to have a set of parameters passed from the UI to NAV, have some business logic performed in NAV including collecting data, creating records etc.,
and then based on that, have a set of records exposed to the UI.

As I see it, I can send a list of parameters to a function in a codeunit, and that function can of course carry out all necessary in NAV, but to be able to expose multiple records to the UI, I probably need to use a page.
I can create a function in a page, but parameters passed to that will be lost on the following WS-call to that page.
In other words, how can I through a single WS-call have
- multiple parameters passed to NAV,
- initiated some business logic to be performed in NAV based on these parameters and
- collected and exposed multiple records from NAV as the “response” to the WS-call.

I am not looking for the .NET code to be performed in UI, but the structure and code-placement inside NAV (C/SIDE).

Hope the above makes sense.
Hope anyone have an example or some hints on “how-to”.

Answers

  • ppavukppavuk Member Posts: 334
    in that case I would use webservices to consume XMl files and run some code depending on XML contents. NAV reply also might be XML. In that case you need only one webservice to communicate whth .net app, just to handle xml transfer. Ok, you need to build xml parser in both ends, but it is quite easy. At least easier than mantain a couple of webservices with different params.
  • kinekine Member Posts: 12,562
    Yes, the simple way is using XMLPort as exposed codeunit function parameter (with Var=yes). In this way you can return the needed records to the calling app and they will be parsed as array of classes.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • RudolfRudolf Member Posts: 10
    Thanks,
    I have made a small example just to asure, that I have got your idea right.

    I have a table, an xmlport and a codeunit.

    The xmlport:


    with a function to set a filter:


    and then the "WS"-codeunit
    with params, var. and code (function):


    First param to be passed to the xmlport, and then the xmlport as second param.

    Is that all, that is needed ? :shock:
    If so, it is elegant in simplicity. :D

    Thanks again.
  • kinekine Member Posts: 12,562
    Do not set the destination for the xmlport. It is set internally. Even you do not need to call export on it, it will be called implicitly at the end of the function if I remmember correctly.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • deV.chdeV.ch Member Posts: 543
    Exactly if you call Export explicitly by code it will be called twice => bad performance!
  • RudolfRudolf Member Posts: 10
    OK, thanks again.

    So I can remove the 5 lines of code, I have shown on my CU-function, and just add my business logic to be performed,
    and effectively all that is needed is the xmlport as var-parameter on the WS-function.

    That is even simpler :D
  • kinekine Member Posts: 12,562
    You need only the SetTypeSelection function to be called, to pass the input parameter into the XML Port... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • RudolfRudolf Member Posts: 10
    Oops - of couse :oops:

    (probably would have noticed it when I come to the real case :) )
  • agentzagentz Member Posts: 14
    there is a website which has already completed a lot of what you are trying to do.
    i just posted the example below of how to create a sales order via webservices and .net. enter sales orders, new customers with credit cards, edit customers, electronic invoices, instant shipping notifications, return authorization lookups with details, blah blah blah.

    it even integrates with zendesk (really easy!).
    everytime something ships, it updates a zendesk ticket with the summary.

    one thing i can tell you is that you're going down a really good coding path! fun stuff!

    if you need help with something specific, i'd be happy to help if i can.


    'create nav sales order object
    Dim navSalesHeader As New SalesHeaderCard
    Dim navShipToCard As New nav.Ship_to_Address.Ship_to_Address
    Dim navCSO As New EDI.createSalesOrder

    With navSalesHeader

    .Document_Type = nav.SalesHeaderCard.Document_Type.Order
    .Document_TypeSpecified = True


    '================================================
    'SET CUSTOMER JUNK
    '================================================
    .Sell_to_Customer_No = poHeader.SoldTo.PartyId
    .Bill_to_Customer_No = poHeader.BillTo.PartyId
    .Originator_UserID = userName

    '================================================
    'SET ORDER JUNK
    '================================================
    .Document_Date = Now.ToString("MM/dd/yyyy")
    .Your_Reference = poHeader.BuyerOrderId
    .Order_Date = Now.ToString("MM/dd/yyyy")
    .Order_DateSpecified = True

    'SET MORE PARAMS HERE...

    end with

    Dim xGen As New XmlGenericOrdering

    Try

    '=====================================================
    docNo = xGen.createSalesOrder(navSalesHeader)
    '=====================================================

    Catch ex As Exception

    Throw

    End Try


    Public Function createSalesOrder(ByVal salesHeader As SalesHeaderCard) As String

    Dim retval As String = ""

    Try

    Dim service As New SalesHeaderCard_Service

    With service

    .Url = System.Web.HttpUtility.HtmlEncode(_wsURL & "Page/SalesHeaderCard")
    .UseDefaultCredentials = False
    .Credentials = _creds
    .Create(salesHeader)

    retval = salesHeader.No

    End With

    Return retval

    Catch ex As Exception

    Throw

    End Try

    End Function
Sign In or Register to comment.