2. These are my notes and references
that I use when consulting and training
on how to use Microsoft Dynamics
NAV Web Services to accomplish
various tasks.
The Basics
There are a handful of steps that are
the same regardless of what task you
are attempting.
1. Identify the Page
2. Publish the Web Service
3. Test the URL in a Web Browser
4. Add a Service Reference to Your
Project
5. Write Some Code.
847-590-3000
info@solsyst.com
3. Identify the Page
Interactions with NAV start with your
requirements. For this sample, we will
assume that you have been asked to
display a list of Items for sale.
Any User Interface in NAV can be
published as a Web Service. This
allows you to manipulate data through
Web Services as if you were using
NAV itself.
This also means that all of Navision’s
validation routines are run when you
attempt to modify data.
So, the first step then, is to identify the
User Interface or “Page” that an end-
user would use to accomplish the task.
Looking around in NAV, you find the
Items for sale in a convenient, “Item
List” interface.
847-590-3000
info@solsyst.com
4. This leads to the biggest “gotcha” with
NAV Web Services. Since you want to
show a list of Items, the intuitive step
would be to use the “Item List”
interface.
This is wrong. What you want to do is
use the single item interface.
For our purposes, that means we want
to use the detail view for one Item (the
“Item Card”) that is accessed by
double-clicking an item in the above
list.
Once you are on the detail page, select
About This Page from the Help
menu.
847-590-3000
info@solsyst.com
5. This opens up a Help Screen that tells
you the Page Name and Number
needed for the next step.
It also tells you the Source Table that
the data comes from in case you want
to poke around in SQL and make sure
you are getting the data you think you
are.
Now we know we want Page 30 – Item
Card.
847-590-3000
info@solsyst.com
6. Publish the Web Service
This is the easy part.
Navigate to the Web Services interface
(Departments->Administration->IT
Administration->General->Web
Services) and select the New button.
Object Type is Page (We’ll talk about
the other types later).
Object ID is 30 – This is the Page
Number that we identified in the earlier
step.
Service Name – This becomes part of
the URL that you use to access the
Web Service, so pick something simple
and memorable. I picked “Item” for this.
Check the Published checkbox.
That’s it. Your Web Service is now
available.
847-590-3000
info@solsyst.com
7. Test the URL in a Web Browser
This is the pattern for your Web
Service URL:
http://<Server>:<WebServicePort>/<S
erverInstance>/WS/<CompanyName>
/Page/<ServiceName>
Microsoft fully explains each piece of
the URL here:
http://msdn.microsoft.com/en-
us/library/dd355398.aspx
Most of the pieces of the URL can be
discovered using the Select Server
dialog in the NAV Role-Tailored Client.
847-590-3000
info@solsyst.com
8. For this sample, Server =
192.168.10.12 – you can use a
Windows Name on your local network
(e.g. NAVSERVER) or).
you can use an internet address such
as (navservices.cronuscorp.net
Although, if you publish over the
internet, you will want to use SSL.
This is a bit beyond the scope of this
article, but you need to send a
Windows Login to NAV Web Services,
so be sure you or your network
administrator fully understand the
security implications of what you are
doing if you expose services over the
public internet.
847-590-3000
info@solsyst.com
9. For SOAP Services Port is 7047 by
default.
The Server Instance in this case is
commercer2
So, the first part of the URL would be:
http://192.168.10.12:7047/commercer2
Finishing up, the next part is the
constant string WS.
847-590-3000
info@solsyst.com
10. The Company Name is the company
you wish to connect to. We will use
CRONUS Supply, Inc. from the Select
Server dialog.
The rest of the information comes from
the Web Services page in NAV where
you published the service.
The next piece is the Object Type from
the Web Services page. Ours will be
Page because that is the only type we
know how to use right now.
Finally, the Service Name is the name
we gave when we published the
service. Item for our example.
This then is our final URL:
http://192.168.10.12:7047/commercer2
/WS/CRONUS%20Supply,%20Inc/Pag
e/Item
847-590-3000
info@solsyst.com
11. If you open that in a Web Browser and
everything has been set up properly,
you will get this XML to the right in reply
This is the simplest way to be sure you
have the URL correct and the
infrastructure is available before you sit
down to write code. If the Web Service
does not send XML to the browser,
then you will need to work with your
Network Administrator to be sure the
services are published and you are
using the correct URL.
847-590-3000
info@solsyst.com
12. Add a Service Reference to Your
Project
After all that, we are ready to open up
Visual Studio and get to work.
I set up a simpleASP.NET Empty Web
Site using the File -> New Web Site
dialog in Visual Studio.
Once you have your project started,
right-click on your project in Solution
Explorer and select Add Service
Reference…
847-590-3000
info@solsyst.com
13. In the Add Service Reference dialog,
paste the URL for the service from the
earlier step and select the Go button.
The Namespace field is how you will
refer to the generated code in your
project, so I like to change the default
to something a bit more descriptive. I
used ItemService for this sample.
847-590-3000
info@solsyst.com
14. Write Some Code
At this point, you are ready to write some code to perform the task at hand.
I will break down some of the more common tasks in separate posts, because the above
preliminary work is the same regardless of the task.
What’s Next?
We get to see some code. The code samples will break out like this:
Simple read of Items
Reading a Header/Line document such as a Sales Quote.
Using Filters to limit the data returned. Sample is Sales Quote for Customer 10000 (The Cannon
Group PLC)
Create a new Sales Order
Overview of Codeunits and other Object Types.
References
MSDN Reference “How to build a URL”: http://msdn.microsoft.com/en-us/library/dd355398.aspx
Want More Microsoft
DynamicsTips?
View My Blog
847-590-3000
info@solsyst.com