web services. service tier web services client services applicationapplication meta data provider...
TRANSCRIPT
WEB SERVICES
Serv
ice T
ier
Web Services
Client Services
Application Meta data provider
Class Library
Clie
nt
Tier
Microsoft SQL Server
Form Builder Data Binder
Role Tailored Client
Data
base
Tie
rHigh Level Architecture
3T architectureServiceTier 95% managed code
Only small part of kernel is unmanagedApplication is compiled to managed code
Business Logic executes on Service Tier“No code” on the Client
Only OCX’s and COM objects
SQL Reporting ServicesStill support for Classic Reports
Web Services…
WebServices - the simple story• Pages and Codeunits can be exposed as
webservices and used by any webservice consumer– Consumer uses Windows Authentication– Supports SSL
DEMO
Strongly typed WS access• Examples
– Adding orders from a Web portal– Invoking Business Logic– Search functionality
• Using– Typically using specially designed Pages &
Codeunits– Visual studio and C#– Running client side (Integration)– Running server side (webapp / process)
DEMO
Initializing the service
Customer_Service service = new Customer_Service();service.UseDefaultCredentials = true;
Creating a filter specification
Customer_Service service = new Customer_Service();service.UseDefaultCredentials = true;
Customer_Filter filter = new Customer_Filter();filter.Field = Customer_Fields.Location_Code;filter.Criteria = "=YELLOW";
Reading the data
Customer_Service service = new Customer_Service();service.UseDefaultCredentials = true;
Customer_Filter filter = new Customer_Filter();filter.Field = Customer_Fields.Location_Code;filter.Criteria = "=YELLOW";
Customer[] customers = service.ReadMultiple(new Customer_Filter[] { filter }, null, 0);
Filling the listbox
Customer_Service service = new Customer_Service();service.UseDefaultCredentials = true;
Customer_Filter filter = new Customer_Filter();filter.Field = Customer_Fields.Location_Code;filter.Criteria = "=YELLOW";
Customer[] customers = service.ReadMultiple(new Customer_Filter[] { filter }, null, 0);
foreach (Customer customer in customers){ this.listBox1.Items.Add(customer.No + " " +
customer.Name + " " + customer.Location_Code);}
Open RTC page with bookmark
string bookmark = service.GetBookmark(customer.Key);System.Diagnostics.Process.Start("DynamicsNAV:////RunPage?
Page=21&mode=View&Bookmark=" + bookmark);
AL-Code for getting a RTC compatible bookmark:
bookmark := FORMAT(ref.RECORDID, 0, 10);
Loosely coupled WS access• Examples
– Edit in Excel• Using
– Generic Page access– Typically Client integration stuff
• Pitfalls– Limited metadata available for pages
DEMO
Get Discovery XML
XMLHTTP xhDisco = new XMLHTTP();xhDisco.open("GET", SendURL, false, DomainUser, Password);xhDisco.send(null);
if (xhDisco.status != 200){ MessageBox.Show(xhDisco.status.ToString() + ": " +
xhDisco.statusText); return;}
XmlDocument xdDisco = new XmlDocument();xdDisco.LoadXml(xhDisco.responseText);
POST ReadMultiple command
XMLHTTP xh4 = new XMLHTTP();xh4.open("POST", SendURL, false, null, null);xh4.setRequestHeader("Content-Type", "text/xml; charset=utf-8");xh4.setRequestHeader("SOAPAction", "ReadMultiple");xh4.send(soapRequest);
XmlDocument rs4 = new XmlDocument();rs4.LoadXml(xh4.responseText);
ReadMultiple XML
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ReadMultiple xmlns="urn:microsoft-dynamics-schemas/page/customer"> <filter> <Field>Balance_LCY</Field> <Criteria>>10,000</Criteria> </filter> </ReadMultiple> </soap:Body></soap:Envelope>
Update XML
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <Update xmlns="urn:microsoft-dynamics-schemas/page/customer"> <Customer>
<Key>300;EgAAAACJCDAxNDU0NTQ1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=19;-3546584706554265600;</Key>
<No>01454545</No> <Name>New Concepts Furniture</Name> <Address>705 West Peachtree Street</Address>………… </Customer> </Update> </soap:Body></soap:Envelope>
Do's and Don'ts• Only expose
WebServices to the internet through a “proxy” (either WebServices or a Portal App.)
• Use GUIALLOWED and ISSERVICETIER to control flow
• Create special pages/codeunits for your strongly typed WS access
• Microsoft Dynamics NAV 2009 WebServices should not be exposed directly to the internet
• Avoid long running transactions
GUIALLOWED vs.ISSERVICETIER• Use GUIALLOWED in your code to
determine whether your code allows user interaction– WS & NAS will have GUIALLOWED = false
• Use ISSERVICETIER in your code to determine whether your code is running managed code on the servicetier or interpreted AL Code on a client or NAS– WS & RTC will have ISSERVICETIER = true
Transactions• Invoke WS method == One transaction
– Commits are ignored– Locks are kept until WS method runs out of
scope• Structure your tables and your code
– Don’t do multiple inserts in one go
Multiple Service Tiers on one box
SC <machine> create Nav<name>binpath= “<exepath> <name>”displayname= “Nav Server <name>”type= ownstart= autodepend= NetTcpPortSharing
SC <machine> create NavWS<name>binpath= “<exepath> <name>”displayname= “Nav Server <name> WS”type= share start= autodepend= NetTcpPortSharing/HTTP
Servic
e Tie
r List
ener
Web
Ser
vice
Liste
ner
Doesn’t
work o
n XP
Performance• WebService and Service Tier caches
– Metadata– JIT Compiled C# code
• Caches are flushed when services are restarted
• Cold access to objects are very slow
JIT compile directory
C:\Documents and Settings\All Users\Application Data\Microsoft\Microsoft Dynamics NAV\60\Server
DEMO
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after
the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.