21
WEB SERVICES

WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

Embed Size (px)

Citation preview

Page 1: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

WEB SERVICES

Page 2: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

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…

Page 3: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

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

Page 4: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

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

Page 5: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

Initializing the service

Customer_Service service = new Customer_Service();service.UseDefaultCredentials = true;

Page 6: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

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";

Page 7: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

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);

Page 8: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

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);}

Page 9: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

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);

Page 10: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

Loosely coupled WS access• Examples

– Edit in Excel• Using

– Generic Page access– Typically Client integration stuff

• Pitfalls– Limited metadata available for pages

DEMO

Page 11: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

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);

Page 12: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

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);

Page 13: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

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>&gt;10,000</Criteria> </filter> </ReadMultiple> </soap:Body></soap:Envelope>

Page 14: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

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>

Page 15: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

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

Page 16: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

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

Page 17: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

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

Page 18: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

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

Page 19: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

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

Page 20: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

JIT compile directory

C:\Documents and Settings\All Users\Application Data\Microsoft\Microsoft Dynamics NAV\60\Server

DEMO

Page 21: WEB SERVICES. Service Tier Web Services Client Services ApplicationApplication Meta data provider Class Library Client Tier Microsoft SQL Server Form

© 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.