Object Models for Distributed Systems

Download Report

Transcript Object Models for Distributed Systems

Presentation 15
SOAP on the Microsoft Platform (.NET)
Outline
• You have already been introduced to SOAP,
WSDL & UDDI on the JAVA platform using AXIS
• Now we will take a look at the MS . NET platforms
SOAP capabilities
• Luckily – SOAP & WSDL are well standardized –
so we do not need to look at these again
• Instead we will:
– Show the counterpart of the AXIS project in .NET - IIS
– Show the alternatives to JAVA development – using the
tools from .NET framework & Microsoft Visual Studio
.NET
Slide 2
Ingeniørhøjskolen i Århus
Apache Tomcat vs. Microsoft Internet
Information Server
•
Apache Tomcat with AXIS & J2SE Java SDK
–
Works on:
•
•
–
Server listening for events:
•
•
–
•
Windows, UNIX, LINUX
Open source Can be compiled to any platform (with some work)
HTTP on port 80 (test http 8080 at startup)
Executes Servlets/JSP and JavaBeans
AXIS is an embedded project within the Tomcat environment but works with most J2EE compliant AS
Microsoft Internet Information Server with the .NET Framework SDK (ASP.NET)
–
Works on:
•
–
Server listening for events:
•
•
–
Only Windows platforms (Windows NT, 2000, XP)
HTTP on port 80 (optional)
Executes Web resources – ASP.NET, Web services, Web forms (resulting in client side HTML ), .NET code
Tightly integrated with the Visual Studio .NET – for easy deployment & debugging
Common code base – but only MS!
SOAP Client
Java, C++, C#,
Delphi, VB
Application
SOAP over HTTP
Web Server
MS Internet Information Server
& the .NET Framework SDK
(ASP.NET)
(vs. Apache Tomcat,
with AXIS & J2SE SDK)
Slide 3
Web
Forms
C++
unman.
Web
Service
Managed
code
Ingeniørhøjskolen i Århus
Web service enabling Windows
• You need to:
– Install .NET Framework SDK
• Download from Microsoft (130 MB)
• Comes standard with Visual Studio 2003 / 2005
– Install Internet Information Server
• Enabled via the Control Panel
• Remember to shut down after using!!!
– Visual Studio .NET
• Already installed (versions 7,7.1, 8 and 9)
• More detailed instructions will follow for the LAB
exercise
Slide 4
Ingeniørhøjskolen i Århus
Not a Windows .NET course
• You will NOT be required to be an expert on .NET
• You will be required to be knowledgeable about it
• History:
– Open source, Java, Linux the WWW threatened MS
– Especially Java was gaining widespread support
amongst developers for its ease of use, productivity
and heterogeneity
– The Empire Strikes back = the .NET Framework
Slide 5
Ingeniørhøjskolen i Århus
Benefits of .NET
• Changes EVERYTHING
– Takes all that was nice in Java and enhances it
– End of DLL incompatibilities, DLL Hell, COM registry hell
– Enter world of VM’s and Java like code (C#) including Garbage
collection – BUT with easy support for legacy unmanaged code
(e.g. C++ for speed) and COM
– Performs much better than Java, and almost equivalent with Win32
C++ applications
– Still only support Microsoft operating systems BUT
– .NET and C# is ECMA standard: Mono (www.go-mono.org) for
Linux is being developed
– IIOP.NET (http://iiop-net.sourceforge.net/index.html) for CORBA
interop
Slide 6
Ingeniørhøjskolen i Århus
The .NET Framework Components
Any language
conforming to the
Common Language
Visual
C#
Specification
Basic C++
(CLS) may be
used.
XML Web Services
For inter-process
communications
Source
code
Compiler
JScript
…
User Interface
ActiveX Data
Objects
ADO.NET and XML
CLR:runtime
execution
environment.
Equlas JVM of
Java. Microsoft
Intermediate
Language (MSIL)
equals Java
ByteCode
Here we find the .NET Remoting libraries
A collection of
class libraries
(over 9000)
wraps Win32 like
Java API
Application
services. E.g.
IIS, Message
Queuing etc.
Perl
3 types of user
interfaces: Web
forms, Windows
forms (Win32),
Command Console
.NET Framework Class Library
Common Language Runtime
COM+
(Transactions, Partitions,
Object Pooling)
Message
Queuing
.NET
Framework
Intermediate
Language
Other IL
libraries
Linker
IIS
WMI
Win32
JIT-compiler only runs first time!
Linked
Program
Slide 7
JIT-compiler
Executable
Program
Ingeniørhøjskolen i Århus
Multiple Language Support
• The .NET Framework is designed to
support many languages
– More than 20 languages currently supported
– Microsoft provides Visual Basic .NET, C#,
Visual J# .NET, and JScript .NET (backwards
compatible with JScript) – others: Delphi
(object pascal)
• Benefits of multiple-language support
–
–
–
–
Code modules are reusable
API access is the same for all languages
The right language is used for the right task
Performance is roughly equal between all
languages (which was not the case in ASP)
Slide 8
Ingeniørhøjskolen i Århus
The Common Language Runtime
• One runtime for all . NET-Based Languages
• Manages threads and memory
– Garbage collection
• Enforces code security
• Eliminates DLL versioning problems
– Multiple versions of a DLL can run simultaneously
– Applications can specify a version of a DLL to use
• Reminds one of the Java Virtual Machine
Slide 9
Ingeniørhøjskolen i Århus
Ressources for learning more
• Feel free to learn more about ASP.NET:
– Getting started with the .NET framework
–
http://msdn.microsoft.com/library/default.asp?url=/library/enus/cpguide/html/cpcongettingstartedwithnetframework.asp
– Link can be found at the course site
– Books on the subject
• Beginning .NET Web Services using C# by Joseph Bustos and
Karli Watsom (WROK forlag)
• More will be listed on the course site
• Other relevant courses at IHA:
– Windows programming (WIN1)
– Komponent baseret udvikling (KPU1)
Slide 10
Ingeniørhøjskolen i Århus
Making the HelloWorld application
• Using Notepad !
• Using Microsoft Visual Studio .NET
• First:
– Install .NET Framework
– Install IIS
• Then:
– Produce code
• Manually for Notepad
• Wizard for Visual Studio
– Deploy in the IIS folder
• \inetpub\wwwroot\
• As an .asmx file
– Test the Web service
• Using the build-in functionality
– Write the Client – and all is well
Slide 11
Ingeniørhøjskolen i Århus
C# Notepad HelloWorld
WebService processing directive for the
ASP.NET environment, e.g. class & language
info
Name(missing): identifies
localname of service
Namespace: the default
namespace for the service
WebService Attribute, for configuration
“behind the scenes” programming
MUCH LIKE JWS
DEPLOYMENT!
Description: a purely
descriptive text information
WebMethod Attribute: indicates that the
following method is to be exposed as a Web
Service method (only public methods are
allowed of course). Allowed properties:
-BufferResponse, CacheDuration, Description,
EnableSession, MessageName,
TransactionOption
Finally: simply store it i web folder
Slide 12
Ingeniørhøjskolen i Århus
Using Visual Studio (managed C++)
Wizards Available: for Managed C++ (see
below example VB and C#
Code-behind: generates .asmx file and code
behind (e.g. .cpp in C++ or .cs in C#)
Slide 13
Ingeniørhøjskolen i Århus
Deploy & Test – access via browser
IIS test : supports viewing WSDL & code testing via browser
WSDL: using ?WSDL
SOAP request & test: small test program generated
Slide 14
Ingeniørhøjskolen i Århus
Developing the Client application
• Support for using Web services in a Visual Studio
application
• Stubs are automatically compiled by Visual Studio
using the “Add Web Reference” function OR
• You may simply use command line tools
Command line usage:
wsdl "http://localhost/hello.asmx" /out:hello.cs
This will produce the hello.cs file which must be compiled as a DLL (using the C# .NET SDK compiler)
csc hello.cs /t:library /out:hello.dll /r:System.Web.Service.dll /r:System.Xml.dll
See example at: http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=35
Slide 15
Ingeniørhøjskolen i Århus
New Application & Add Web Reference
Add Web Reference:
Visual Studio support for
generating a proxy using
WSDL document
Slide 16
Ingeniørhøjskolen i Århus
Discover & bind the Web service
Add Web Reference:
Just enter the Web
service endpoint address
Slide 17
Ingeniørhøjskolen i Århus
Visual Studio produces a Proxy DLL
Performed by Visual Studio tool:
a DLL is generated (Web Service
Proxy Generator), and a header file
and a WSDL support document is made
available
Slide 18
Ingeniørhøjskolen i Århus
Proxy class DLL
• DLL is generated by Visual Studio
• The generated Proxy class derives from
System.Web.Service.Protocols.SoapHttpClientProtocol
• It contains the following properties
– ClientCertificates allows clients to pass Authenticode X.509 v.3
certificates
– CookieContainer for handling state
– Credentials for authentication purposes
– PreAuthenticate saves the roundtrip by sending credentials first
– Proxy use this property if you need to pass a proxy
– Timeout default 100.000 milisseconds – may be set for infinite
– Url from the location attribut of the service used
Slide 19
Ingeniørhøjskolen i Århus
using System.Diagnostics;
using System.Xml.Serialization;
using System;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Web.Services;
The Proxy code generated by the
WSDL Proxy generator
/// <remarks/>
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="HelloWorldSoap", Namespace="http://www.wagner.dk/webservices")]
public class HelloWorld : System.Web.Services.Protocols.SoapHttpClientProtocol {
public HelloWorld() {
this.Url = "http://192.168.1.100/hello.asmx";
}
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.wagner.dk/webservices/Hello",
RequestNamespace="http://www.wagner.dk/webservices", ResponseNamespace="http://www.wagner.dk/webservices",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string Hello(string myName) {
object[] results = this.Invoke("Hello", new object[] {
myName});
return ((string)(results[0]));
}
public System.IAsyncResult BeginHello(string myName, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("Hello", new object[] {
myName}, callback, asyncState);
}
public string EndHello(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((string)(results[0]));
}
}
Slide 20
Ingeniørhøjskolen i Århus
Write the C++ code
Slide 21
Ingeniørhøjskolen i Århus
Try it out
Not that much fun with command line … lets make a proper Windows solution
Slide 22
Ingeniørhøjskolen i Århus
Piece of Cake – Now C#
Simple C# Windows
Form Application:No
point in producing another
command line app
Add Web Reference:
Again we use the Web
service endpoint address
with the “Add Web
Reference” feature
We add a button, a text
field and a label.
Clicking the button
gives access to the
event handler
“OnClick” of the button
Slide 23
Ingeniørhøjskolen i Århus
C# - coding the connection
Using the Proxy DLL:
We recognize the
connection between the
WSDL, the DLL and the
C# client code
Slide 24
Ingeniørhøjskolen i Århus
Heterogeneous system C# to Java
C# to Java Lets change it
to our Axis Web service
// Hello World.Java
public class HelloWorld {
public HelloWorld() {
}
public String getHelloWorldMessage(String name) {
return "Hello World to "+name;
}
}
private void button1_Click(object sender,
System.EventArgs e)
{
localhost.HelloWorldService hello =
new localhost.HelloWorldService();
textBox1.Text =
hello.getHelloWorldMessage("Stefan");
}
Proxy DLL stub
generated by VS
Add Web Reference: We
need to generate a new
Proxy DLL
Other way around: and of course it also works the other way around
Slide 25
Proxy skeleton class
generated by AXIS
Proxy: if we are not using
.JWS deployment, we
need to generate the
skeleton classes in AXIS
as well
Ingeniørhøjskolen i Århus
Try it with C++
• WARNING: In VS7 there
seems to be a bug!
– Problem with port 8080
– Need to manually paste the
WSDL file and compile the
proxy stub DLL
– This works fine in C#
– No problem in VS7.1
– Not tested with VS 8.0 / 9.0
Slide 26
Ingeniørhøjskolen i Århus
NOT ONLY .NET
• You may use legacy C++ with ATL to create non
.NET Web services & clients
• Producing a server:
– http://msdn.microsoft.com/library/default.asp?url=/librar
y/enus/vccore/html/vcconatlserverprovidingwebservices.asp
• Producing a client:
– http://msdn.microsoft.com/library/default.asp?url=/librar
y/enus/vccore/html/vcconATLServerCreatingWebServiceCli
ents.asp
Slide 27
Ingeniørhøjskolen i Århus
Not Only VS IDE Support – Java as Well
IDE backed by SUN (free): Netbeans – has WS support
Slide 28
Ingeniørhøjskolen i Århus
Slide 29
Ingeniørhøjskolen i Århus
Ohter Java IDE’s with WS support
•
•
•
•
•
•
Netbeans (SUN backed, free)
Eclipse(IBM backed, free)
JDeveloper (Oracle tool, free)
JBuilder (Borland, commercial)
IntelliJ-Idea (IntelliJ, commercial)
Others?
Slide 30
Ingeniørhøjskolen i Århus