NAV 2013 WebService inspiration needed

Rudolf
Member Posts: 10
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”.
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”.
0
Answers
-
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.0
-
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.0
-
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.
Thanks again.0 -
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.0
-
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 simpler0 -
You need only the SetTypeSelection function to be called, to pass the input parameter into the XML Port... ;-)0
-
Oops - of couse :oops:
(probably would have noticed it when I come to the real case)
0 -
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 Function0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions