Presentation is loading. Please wait.

Presentation is loading. Please wait.

Exposing and Consuming Web Services with.NET Tutorial 33.

Similar presentations


Presentation on theme: "Exposing and Consuming Web Services with.NET Tutorial 33."— Presentation transcript:

1 Exposing and Consuming Web Services with.NET Tutorial 33

2 XML Web Services in.NET casey# (pronounced kc-sharp) chesnut brains-N-brawn.com OOPSLA October 15, 2001

3 Copyright © 2001 by iigo, Inc. 3 Presentation Style •Informal •Interrupt for topical questions –Notice agenda •Save off topic questions until end •Fun

4 Copyright © 2001 by iigo, Inc. 4 Agenda •Introduction •Standards •Exposing •Consuming •Non functional •Case Study •Questions

5 Copyright © 2001 by iigo, Inc. 5 Hype •3 rd generation of the Internet –Distributed communication •Government and Academic •No revenue model –HTML presentation of backend DBMS •Dot Com •Advertising crash –Web Services … •Most compelling reason to.NET

6 Copyright © 2001 by iigo, Inc. 6 Where They Fit In.NET Base Class Library Common Language Specification Common Language Runtime ADO.NET: Data and XML VBC++C# Visual Studio.NET ASP.NET: Web Services and Web Forms JScript… Windows Forms

7 Copyright © 2001 by iigo, Inc. 7 What Are They? •Application logic exposed programmatically over the internet •Based on standards that are neither platform, vendor, language dependent •Data and functions, NOT user interface •COTS on the web

8 Copyright © 2001 by iigo, Inc. 8 DEMO – Hello World •Build from scratch (Without VS.NET) •Minimal client –Send/Receive HTTP –Process XML

9 Copyright © 2001 by iigo, Inc. 9 Why Do We Need Them? •Current distributed computing paradigms are lacking •Make business logic accessible everywhere –Internal and external systems –Variety of clients

10 Copyright © 2001 by iigo, Inc. 10 Current Distributed Computing Paradigms •DCOM, RMI, IIOP –Heavyweight –Not interoperable •Screen-scraping –Brittle

11 Copyright © 2001 by iigo, Inc. 11 Business Logic Accessibility (Systems) Web Service Web Service Business Partner HTML Front-End Intranet App

12 Copyright © 2001 by iigo, Inc. 12 Business Logic Accessibility (Clients) Web Service Generic Browser Wireless Cell Phone Wireless Pocket PC Dedicated Client ?

13 Copyright © 2001 by iigo, Inc. 13 Who Is Involved? •Microsoft •DevelopMentor •UserLand •IBM •Lotus •Ariba •HP •Sun •W3C •BEA •…

14 Copyright © 2001 by iigo, Inc. 14 How Do They Work? Consumer Web Service Provider Description Discovery Communication

15 Copyright © 2001 by iigo, Inc. 15 Web Service Standards •Discovery (XML) –UDDI –DISCO •Description (XML) –WSDL •Communication (XML, HTTP …) –SOAP, XSD •OTHER –SOAP-RP, DIME, XLANG, WSFL, XSL(T) …

16 Copyright © 2001 by iigo, Inc. 16 Discovery •UDDI (Universal Discovery and Description Interface) –Directory •DISCO –Static –Dynamic •Word of Mouth, …

17 Copyright © 2001 by iigo, Inc. 17 UDDI •Centralized directory of Business and Web Services •Has an API which is exposed as a Web Service •Replicated among uddi.microsoft.com, IBM, Ariba is back in! … HP soon •uddi.org/specification.html

18 Copyright © 2001 by iigo, Inc. 18 DISCO •XML file for discovering a service contract, and related resources. •Web crawlers can be used to auto discover services •Least solid of the specs •msdn.microsoft.com/xml/general/disco. asp

19 Copyright © 2001 by iigo, Inc. 19 DISCO Examples •Static: •Dynamic:

20 Copyright © 2001 by iigo, Inc. 20 DEMO - DISCO •http://localhost/default.vsdisco

21 Copyright © 2001 by iigo, Inc. 21 Description •WSDL (Web Service Description Language) •Describes protocols, operations, parameters, return values, … •Used to generate proxy objects so clients can easily consume the service •msdn.microsoft.com/xml/general/wsdl. asp

22 Copyright © 2001 by iigo, Inc. 22 XML Schema •Define content, structure, semantics of XML documents •Like a DTD, but written as XML •Replaces DTDs •W3C Recommendation in May •Schema repositories

23 Copyright © 2001 by iigo, Inc. 23 DEMO – WSDL •Show auto-generated WSDL file

24 Copyright © 2001 by iigo, Inc. 24 Communication •HTTP GET –Parameters in query string (limited) •HTTP POST –Name/value pairs in body (ad hoc) •SOAP –Predominantly HTTP POST w/ XML –SMTP for asynchronous calls … –Complex data types

25 Copyright © 2001 by iigo, Inc. 25 Marshal Types •HTTP GET/POST –Primitives –Enums –Arrays of above •SOAP –Primitives, Enums –Classes, Structs –DataSets –XmlDoc, XmlNodes –Arrays of above

26 Copyright © 2001 by iigo, Inc. 26 SOAP •SOAP (Simple Object Access Protocol) –SOAP == HTTP + XML [de facto] –SOAP != HTTP + XML [SOAP <> HTTP + XML … for VB’ers  ] •Message Format •SMTP … •msdn.microsoft.com/xml/general/soaps pec.asp

27 Copyright © 2001 by iigo, Inc. 27 SOAP/XML/HTTP •HTTP is the transport protocol –Other protocols can be used as well •SOAP is the wire protocol (XML) –What the message should look like on the wire •XML is used to describe the SOAP message and the data being passed and returned to the service

28 Copyright © 2001 by iigo, Inc. 28 SOAP Message •HTTP Request/Response –HTTP Headers •SOAPAction Header –HTTP Body •SOAP Envelope –Optional SOAP Headers –Mandatory SOAP Body »Boxcar Method calls –Referenced XML Data

29 Copyright © 2001 by iigo, Inc. 29 Entire SOAP Message POST /news/groups.asmx HTTP/1.1 Content-Length: 504 Content-Type: text/xml Host: localhost User-Agent: MS Web Services Client Protocol 1.0.2204.21 SOAPAction: "http://tempuri.org/GetNewMessageHeaders“ // comment // followed by CRLF’s before HTTP body

30 Copyright © 2001 by iigo, Inc. 30 Entire SOAP Message … 010618 164431 dnug.test

31 Copyright © 2001 by iigo, Inc. 31 SOAP Request casey

32 Copyright © 2001 by iigo, Inc. 32 SOAP Response Hello casey

33 Copyright © 2001 by iigo, Inc. 33 SOAP Fault Server BAD URL

34 Copyright © 2001 by iigo, Inc. 34 SOAP Process •Client calls method on proxy object •Proxy object serializes parameters, and sends SOAP request •Server receives SOAP request, and deserializes parameters •Method is run on server •Results are serialized and send as a SOAP response or fault •Proxy object receives SOAP, and deserializes the results to return to client

35 Copyright © 2001 by iigo, Inc. 35

36 Copyright © 2001 by iigo, Inc. 36 Coding.NET Web Services •Plumbing is automatically taken care of: –UDDI does not have to be done –DISCO is auto –WSDL is auto –SOAP de/serialization is auto •Concentrate on business logic •Concentrate on non-func. requirements

37 Copyright © 2001 by iigo, Inc. 37 Demo – VS.NET •Create simple Web Service •Consume with auto-generated client

38 Copyright © 2001 by iigo, Inc. 38 Passing Parameters •Primitives for the auto-generated help page •out parameters are SOAP only •SOAP Headers –SoapHeader Class –SoapHeader Attribute •in/out direction •required bool

39 Copyright © 2001 by iigo, Inc. 39 Return Value(s) •You have 1 return value … use it wisely •Throw exception, not HRESULT style •SOAP can manage multiple returns public string RetTwoStrings(out string b) Returned as value following Mandatory Soap Body Does not work for HTTP Get/Post Return null for empty sets

40 Copyright © 2001 by iigo, Inc. 40 DEMO - DataSet •In-memory Database –tables, rows, relations, constraints •Can strongly-type with XSD –schema compiler •Built-in support for errors –Tables – bool HasErrors() –Rows – Rows[] GetErrors()

41 Copyright © 2001 by iigo, Inc. 41 Exceptions •Exceptions are promoted to SoapExceptions •SoapExceptions are serialized to SOAP faults •Also the possibility for standard HTTP exceptions before SOAP processing occurs •Set errors within DataSets/XmlDocs

42 Copyright © 2001 by iigo, Inc. 42 State(less) •Should design stateless, or pass state in method calls/headers … unless state is too large to keep passing back and forth –Session State –Application State •Shared among all instances of service

43 Copyright © 2001 by iigo, Inc. 43 Caching •SOAP response payloads can be cached on the server •Beta 1 Hack –Write off to XmlDocument on server, and then return that XmlDoc based on time

44 Copyright © 2001 by iigo, Inc. 44 Asynchronous •Automatically get Begin/End methods Services s = new Service(); IAsyncResult ar = s.BeginLongTime(null); //wait if(ar.IsCompleted == true) {string result = s.EndLongTime(ar);}

45 Copyright © 2001 by iigo, Inc. 45 Asynchronous BeginMethod() IsComplete() false IsComplete() true EndMethod () result

46 Copyright © 2001 by iigo, Inc. 46 WebService Attributes [WebService… (Description=“blah”)] (Description=“ docs ”)] (Namespace=“http://dnug.net/service”)] (Name=“ServiceName”)]

47 Copyright © 2001 by iigo, Inc. 47 WebMethod Attributes [WebMethod… (Description=“blah”)] (Transaction=Transaction.Required)] (EnableSessionState=False)] (CacheDuration=20)] (BufferResponse=“true”)] (MessageName=“MethodName”)]

48 Copyright © 2001 by iigo, Inc. 48 Help Page •Modify ASP.NET web configuration •Modify default ASP.NET web help page –Documentation –Branding –GET/POST –…

49 Copyright © 2001 by iigo, Inc. 49 XML Attributes [XmlInclude(typeof(foo))] [XmlAttribute()] [SoapAttribute()] [XmlElement()] [SoapElement()] [XmlArray()] [SoapArray()]

50 Copyright © 2001 by iigo, Inc. 50 Entry Points •Global.asax –Application_Begin/EndRequest() –Session_Start/End() –HTTP Request/Response •SOAP Extensions –SOAP Message before request deserialization and after response serialization –Roll your own SOAP implementation

51 Copyright © 2001 by iigo, Inc. 51 DEMO – SOAP Extension •Request / Response •Before / After (De)serialization •Client / Server

52 Copyright © 2001 by iigo, Inc. 52 Service Design Tips •Don’t change interface; additional data can be returned without harm •Make flexible to support all possible clients •Validate on server, you do not control the client •Provide test instance for people to code against

53 Copyright © 2001 by iigo, Inc. 53 Service Design Tips •Provide client examples for different consumers •Provide simple type example for testing •Find a standard schema to use •Ping() •Beware denial of service •Make chunky calls, reduce network trips •…

54 Copyright © 2001 by iigo, Inc. 54 Service Design Web Service Component Consumer chunky chatty

55 Copyright © 2001 by iigo, Inc. 55

56 Copyright © 2001 by iigo, Inc. 56 DEMO – Consuming Services •Create client •Add Web Reference •Call method •Display DataSet

57 Copyright © 2001 by iigo, Inc. 57 Discovering •Can discover at design or run time –Web based registry –Exposed as web services

58 Copyright © 2001 by iigo, Inc. 58 UDDI tModel Client UDDI Repository My Web Service Competitor’s Web Service tModel URL

59 Copyright © 2001 by iigo, Inc. 59 Proxy •Can occur at design or run time •SOAP by default •Store URL in XML config file •Firewall authentication •Timeout •Cookie support

60 Copyright © 2001 by iigo, Inc. 60 Exceptions •HTTP •SOAP Try{//make web service call} Catch(SoapException){ //SOAP } Catch(Exception){ //HTTP } Finally {}

61 Copyright © 2001 by iigo, Inc. 61 DEMO - Exceptions •Parsing parameters •SOAP Fault •HTTP Error

62 Copyright © 2001 by iigo, Inc. 62 Client Design Tips •Cache data if disconnected •Have fail-over if a service is down •Dynamically discover services based on a schema •Don’t code to ith-index, reference Xml nodes explicitly in case schema changes

63 Copyright © 2001 by iigo, Inc. 63 Non-Functional •Security •Auditing •Deployment •Reliability •Performance •Maintainability •Usability •Scalability

64 Copyright © 2001 by iigo, Inc. 64 Security •IIS (Basic, Digest, Kerberos, …) •User/Pass as Service parameters •Login method which returns a session, make session a parameter of other calls •User/Pass in Soap Header •Certificates / SSL / HTTPS •Passport Service •Public/Private encrypt at client, server

65 Copyright © 2001 by iigo, Inc. 65 DEMO - Encryption •Encryption algorithms are platform/language independent •Symmetric •PGP

66 Copyright © 2001 by iigo, Inc. 66 What Else Is There? •.NET Remoting •XML-RPC •ebXML •BXXP •BizTalk •ATL Server

67 Copyright © 2001 by iigo, Inc. 67 When Do We Start? •Beta 2 •SOAP Toolkit is for DNA projects •.NET supercedes SOAP Toolkit •More wireless clients all the time •More specs. coming all the time

68 Copyright © 2001 by iigo, Inc. 68 3 rd Party Services •HailStorm / My Services •UDDI •eBay •XMethods •SalCentral •…

69 Copyright © 2001 by iigo, Inc. 69 Case Study - Problem •ListServs –Fills up email box and harddrive –Moderated vs Unmoderated lists •Newsgroups –Lacks notification feature –Port 119 might be blocked

70 Copyright © 2001 by iigo, Inc. 70 Case Study – Architecture News Server NNTP Web Service Dedicated Client Firewall Outlook Express

71 Copyright © 2001 by iigo, Inc. 71 Case Study – Future MS News Server NNTP Web Service Dedicated Client @Home News Server Web Client Mobile Client Outlook Express

72 Copyright © 2001 by iigo, Inc. 72 SOAP over NNTP •True Asynchronous •Messaging is almost identical to SMTP •WSDL?

73 Copyright © 2001 by iigo, Inc. 73 Other Demos •XSLT •User Objects •Typed DataSet •XML Server Control

74 Copyright © 2001 by iigo, Inc. 74 Summary •Web Services allow heterogeneous distributed systems to communicate •Standard adoption and support is growing •Powerful new model for application development •.NET Framework makes developing Web Services easy •Likely to live-up to the hype

75 Copyright © 2001 by iigo, Inc. 75 Online Resources •msdn.microsoft.com/webservices •msdn.microsoft.com/theshow •W3C.org •soap-wrc.com •xmethods.com •sys-con.com/webservices

76 Copyright © 2001 by iigo, Inc. 76 Questions •???


Download ppt "Exposing and Consuming Web Services with.NET Tutorial 33."

Similar presentations


Ads by Google