www.monash.edu.au.net xml web services monash university semester 1, march 2006
TRANSCRIPT
![Page 1: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/1.jpg)
www.monash.edu.au
.NET XML Web Services
Monash University
Semester 1, March 2006
![Page 2: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/2.jpg)
www.monash.edu.au
2
Overview
• Current Business Models• What are XML Web Services and why use
them• How web services are developed
using .NET• Extensions to Web Services using .NET
![Page 3: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/3.jpg)
www.monash.edu.au
3
Business Applications 3-tier
• Business applications must separate software into 3 tiers
• Separate the business process from the user interface and data layers
User Interface
Business Objects
Data Layers
![Page 4: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/4.jpg)
www.monash.edu.au
4
Extend your business
• With 3-tier architecture, you restrict your business to your applications
• With global economy, you want different global companies to use your software
• Need to provide another tier to your business process
• Service Oriented Architecture is what can be used to expose your business to the software world
![Page 5: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/5.jpg)
www.monash.edu.au
5
Service Oriented Architecture
ProviderConsumer
Broker
PublishSearch
Bind/Invoke
![Page 6: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/6.jpg)
www.monash.edu.au
6
What are XML Web Services
• W3C Definition– “… software application identified by a URI,
whose interfaces and binding are capable of being defined, described and discovered by XML artefacts and supports direct interactions with other software applications using XML based messages via internet-based protocols.”
![Page 7: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/7.jpg)
www.monash.edu.au
7
Distributed Programming Model
Client Server
Web Services Description Language (WSDL)
Server StubClient Proxy
SOAP, XML-RPC
Transport (HTTP, FTP, IIOP etc.)
![Page 8: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/8.jpg)
www.monash.edu.au
8
Why XML Web Services
• Supports n-tier Application Architecture (Façade Pattern should be used)
• Provide a web interface to you current business infrastructure
• Use web protocols and standards to communicate and transfer information
• Can be used to communicate through firewalls that block other Distributed Programming models
![Page 9: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/9.jpg)
www.monash.edu.au
9
WebService
RMIService
DCOMService
Consumer
Firewall
Port 80
Web Services and Firewalls
![Page 10: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/10.jpg)
www.monash.edu.au
10
Web Services Standards and Protocols
• Open Web Protocols– HTTP, XML, SOAP etc.
• Web Services Contracts/Description– WSDL
• Advertising and Discovery– UDDI, Disco
![Page 11: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/11.jpg)
www.monash.edu.au
11
Service Oriented Architecture
ProviderConsumer
Broker
PublishSearch
Bind/Invoke
Applications
UDDI
WSDL
![Page 12: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/12.jpg)
www.monash.edu.au
12
Business Applications n-tier
Web Service Web Service
Communication
![Page 13: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/13.jpg)
www.monash.edu.au
13
ASP.NET XML Web Services
• Must use an .ASMX file to create or generate a Must use an .ASMX file to create or generate a web interfaceweb interface
• An ASMX file can contain code or point to a An ASMX file can contain code or point to a DLL using Code behind DLL using Code behind
• Must inherit from Must inherit from System.Web.Services.WebService or System.Web.Services.WebService or implement System.Web.Services.WebService implement System.Web.Services.WebService as a custom attribute of your classas a custom attribute of your class
![Page 14: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/14.jpg)
www.monash.edu.au
14
Demonstration HelloWorldWS
• Basic Hello World in .NET
![Page 15: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/15.jpg)
www.monash.edu.au
15
Create a Web Service in ASP.NET
• Declaring Web Services– .ASMX file
• Implementation– .CS file
public class HelloWorld: System.Web.Services.WebServiceSystem.Web.Services.WebService{{
[WebMethod][WebMethod]public string Hello ()public string Hello (){{
return “Hello World”;return “Hello World”;}}
}}
<%@ WebService Language="C#" Class=“MonashIT.HelloWorld,MonashITLibrary" %>
![Page 16: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/16.jpg)
www.monash.edu.au
16
Web Method
• Description - a property which makes a Description - a property which makes a description available to a WSDL filedescription available to a WSDL file
• MessageName - the method name used when MessageName - the method name used when calling a Web Method calling a Web Method
• Enable Session - defines whether a session Enable Session - defines whether a session state is enabledstate is enabled
• TransactionOption - indicates transaction TransactionOption - indicates transaction supportsupport
• CacheDuration – defines the length of time the CacheDuration – defines the length of time the method invocation should be cached formethod invocation should be cached for
![Page 17: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/17.jpg)
www.monash.edu.au
17
Stateless and Statefull services
• Stateless means a web service losses its state
• Web services are normally stateless• Usually provide access to state information
such as databases and XML files• .NET Web services are stateless by default• More will be covered in Module 8
![Page 18: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/18.jpg)
www.monash.edu.au
18
Publishing Web Services
• Files– Web.Config and Global.asax file
– Assemblies and .asmx files
• IIS structure– Must create a virtual directory
– Must ensure that the web service has appropriate permissions to access and modify resources
![Page 19: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/19.jpg)
www.monash.edu.au
19
Consuming Web Services
• Accessing Web Services from IE– Demonstration
• Proxy class• WSDL tool
– Generate source file. Need to compile– Default is in C#
• Visual Studio .NET automates this process by creating
wsdl http://localhost/hello/HelloWorld.asmx?wsdl
![Page 20: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/20.jpg)
www.monash.edu.au
20
Demonstration
• A stock service demonstration
http://localhost/StockTradingService/StockService.asmx
localhost/WapStockClient/Stocks.aspx
![Page 21: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/21.jpg)
www.monash.edu.au
21
WS State Management
• Statement management objects– Application
– Session
• EnabledSession property in WebMethod attribute– To enable Session object.
![Page 22: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/22.jpg)
www.monash.edu.au
22
State Management
• Web Services are stateless• Use ASP.NET session state mechanism
– Restricted to a logical application
– Context in which a user communicates to a server
– Functionality> Request identification and classification> Store data across multiple requests> Session events> Release of session data
– .NET State Server Process
![Page 23: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/23.jpg)
www.monash.edu.au
23
State Management
• Each request of a Web Service its class instance is instantiated and thrown away when it is no longer used– i.e. each time you call a method the class
variable values are not available be the web service has be re-instantiated
• If data is required to be used between different requests, the ASP.NET built-in session state mechanisms must be used
![Page 24: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/24.jpg)
www.monash.edu.au
24
State Management (cont…)
• Web services have access to the same state management options as other ASP.NET applications such as the Session and Application objects and cookies
• Data stored in the Session object is available only when the EnableSession property of the WebMethod attribute is set to true. Access to the Application object is automatic however
![Page 25: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/25.jpg)
www.monash.edu.au
25
State Management (e.g.)
• Declaring a Web service method, with the EnableSession property equal to WebMethod attribute to true.
[WebMethod(EnableSession=true)][WebMethod(EnableSession=true)]public string YourName(string name)public string YourName(string name){{ if(Session["Name"] == null)if(Session["Name"] == null) Session.Add("Name", name);Session.Add("Name", name);
return Session["Name"].ToString();return Session["Name"].ToString();}}
[WebMethod(EnableSession=true)][WebMethod(EnableSession=true)]public string YourName(string name)public string YourName(string name){{ if(Session["Name"] == null)if(Session["Name"] == null) Session.Add("Name", name);Session.Add("Name", name);
return Session["Name"].ToString();return Session["Name"].ToString();}}
[WebMethod(EnableSession=true)][WebMethod(EnableSession=true)]public string GetName()public string GetName(){{ if(Session["Name"] == null)if(Session["Name"] == null) return "no name recorded";return "no name recorded"; elseelse return Session["Name"].ToString();return Session["Name"].ToString();}}
[WebMethod(EnableSession=true)][WebMethod(EnableSession=true)]public string GetName()public string GetName(){{ if(Session["Name"] == null)if(Session["Name"] == null) return "no name recorded";return "no name recorded"; elseelse return Session["Name"].ToString();return Session["Name"].ToString();}}
![Page 26: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/26.jpg)
www.monash.edu.au
26
Caching
• Uses the ASP.NET Caching Model• Improves the performance of application by
caching messages
Parser
Assembly CacheMemory
ComplierOutput C
ache
Key
Normal
Cached
![Page 27: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/27.jpg)
www.monash.edu.au
27
Web Service Execution Model
• Synchronous– Like any other call to class methods
• Asynchronous– Split the method into two code blocks
> BeginMethodName> EndMethodName
– CLR determines if and when operation has finished
![Page 28: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/28.jpg)
www.monash.edu.au
28
Asynchronous invocation
• Exposed in generated proxy class– Begin and End method
• Begin method– Return IAsyncResult
– Parameters > AsyncCallback> Object
• End method– Return function return type
– First parameter is IAsyncResult
![Page 29: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/29.jpg)
www.monash.edu.au
29
Demonstration
• Building an application that supports asynchronous invocation
![Page 30: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/30.jpg)
www.monash.edu.au
30
Transaction Support in Web Services
• Same as COM+ and Microsoft Transaction Server
• Declarative Transaction• TransactionOption property in WebMethod
attribute
![Page 31: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/31.jpg)
www.monash.edu.au
31
Windows security
• Client application– NetworkCredential class
> Username, password, domain
– CredentialCache class
– Credentials property in proxy class
![Page 32: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/32.jpg)
www.monash.edu.au
32
Web Services Security
• ASP.NET Security– Windows security, IIS security
– Web.config file
• Customised SOAP-based security– SOAP Header
![Page 33: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/33.jpg)
www.monash.edu.au
33
SOAP Header
• Inherit from SOAPHeader class• Declare a public attribute• Apply SOAPHeader attribute to
WebMethod– MemberName property
• However, this is .NET specific
![Page 34: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/34.jpg)
www.monash.edu.au
34
Global XML Architecture
• GXA provides uniform way of using XML web services
• A Microsoft specific initiative to web services• Supports new extensions to web services• Implemented in .NET using Web Services
Enhancements
![Page 35: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/35.jpg)
www.monash.edu.au
35
Web Services Enhancements 2.0
• Provides additional Web Services capabilities• Additional WS specifications
– WS-Security
– WS-Policy
– WS-Trust
– WS-Addressing
– Etc.
![Page 36: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/36.jpg)
www.monash.edu.au
36
WS-Security
• By OASIS• Enhancements to
SOAP messaging• A general purpose
mechanism for secure messaging
• Support symmetric and public key technologies
![Page 37: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/37.jpg)
www.monash.edu.au
37
WSE 2.0 Demo
• Using Asymmetric Encryption• Using digital certificates
![Page 38: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/38.jpg)
www.monash.edu.au
38
Web Service Technologies
• EJB using Tomcat & Sun ONE toolkit• BEA Weblogic• IBM Web Sphere • .NET using ASP.NET and IIS• Many more available
![Page 39: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/39.jpg)
www.monash.edu.au
39
Communication between systems
![Page 40: Www.monash.edu.au.NET XML Web Services Monash University Semester 1, March 2006](https://reader035.vdocuments.us/reader035/viewer/2022070307/551b3e7c550346d41a8b55c1/html5/thumbnails/40.jpg)
www.monash.edu.au
40
Conclusion
• Businesses use web services for interoperability
• .NET offers web services through ASP.NET
• ASP.NET provides caching and supports the Global XML architecture through Web Services extensions