You are on page 1of 9

Goals

• Introduce a number of real-world technologies

CS 5381 Topics in Software – .NET


– Web Services
Development – ASP, SOAP, XML
Web Services using .NET • To learn how web services can be implemented
– .NET framework
Dr. Steve Roach – Visual Studio
University of Texas at El Paso • To study issues related to web services
Department of Computer Science – Application design
Spring 2004 – Security

This course Syllabus

• This is a course about .NET and web services. • Texts


– It is not a programming course. • Policies
– I expect you to be able to learn how to use the tools available • Attendance
on your own. • Programs
• I am not an expert in .NET, C#, or web services. • Papers
– I will be learning this along with you.
– My goals are to know enough about how web services work
and how to implement them that we can use web services in
the research group.
• This course will be very hands-on.
– Expect to spend some time writing and running programs.
– Don’t expect that I know how to do some of the things I assign.
– You will have to do some leg work to get things running.

3 4

Example: a "real world" application

• Here's a common application design in industry:

The .NET Architecture Presentation Business Data Access


DB

DB

Browser Web
Client Page

Server
Generic
Client
Web Server DB

GUI
Client Server

Host Process
Server
6
Microsoft .NET Influences

• based on the .NET Framework, • .NET is the result of many influences…


– the Common Language Runtime (CLR)
– an extensive set of Framework Class Libraries (FCL).
OOP JVM
• “The CLR defines a common programming model and a standard
type system for cross-platform, multi-language development.”
– Managed execution
– Application designs GUI
– .NET execution model .NET Web

component-based
design n-tier design

7 8

.NET is multi-language .NET is cross-platform

• .NET supports VB, C# (C-sharp), C++, J# (Java 1.2), Eiffel, etc. • Compiled .NET apps run on any supported platform:

code.vb code.cs code.cpp ...


APP.exe

Development Tools FCL

?
Win64 Win32 WinCE
app.exe (XP,2K,98)

9 10

How is cross-platform achieved? (1) FCL

• Cross-platform execution realized in two ways: • Framework Class Library


– 1000's of predefined classes
1. apps are written against Framework Class Library (FCL), not
underlying OS – common subset across all platforms & languages
– networking, database access, XML processing, GUI, Web, etc.
2. compilers generate generic assembly language which must be
executed by the Common Language Runtime (CLR)

• Goal?
– FCL is a portable operating system

11 12
(2) Managed execution Implications of .NET's execution model

• Common Language Runtime must be present to execute code: 1. Clients need CLR & FCL to run .NET apps
– available via Redistributable .NET Framework
APP.exe – 20MB download
– runs on 98 and above, NT (sp6a) and above
OS Process

JIT Compiler other FCL


components 2. Design trade-off…
+ managed execution (memory protection, verifiable code, etc.)
obj code Core + portability:
FCL – slower execution?
CLR

Underlying OS and HW

13 14

.NET vs Java

• Both use virtual machine; .NET JIT Compiled

code.vb code.cs code.cpp code.java


Application Development:
Monolithic vs components
CLR FCL JVM JFC

Win Unix Mac Win Unix Mac


15

Monolithic Component-based

• Monolithic app: all source code compiled into one .EXE • Component-based app: .EXE + 1 or more .DLLs

main.cs compute.cs data.cs compute.cs


main.cs

compute.dll

GUI.exe
APP.exe data.cs

data.dll

– *not* the norm on Windows… – standard practice on Windows…

17 18
Why component-based? Example: n-tier design

• Many motivations: • Many applications are designed with N levels or "tiers"


– team programming – good separation of concerns
– multi-language development (I like VB, you like C#) – enables reuse of back-end tiers across varying FEs
– code reuse (e.g. across different .EXEs)
– independent updating (can update just component X)
object object
Front-end

object
• FCL ships as a set of components!

Presentation Business Data Access Data

19 20

Assemblies

• .NET packages components into assemblies


• 1 assembly = 1 or more compiled classes
– .EXE represents an assembly with classes + Main program
– .DLL represents an assembly with classes
.NET execution model…
code.vb
code.vb
code.cs

Development Tools

.EXE / .DLL
assembly

22

CLR-based execution revisted Assembly resolution


• CLR must be able to locate all assemblies: • How does CLR find assemblies?
.DLL – Windows currently uses a database called the "registry"
.EXE .DLL
.DLL – the registry is gone in .NET

OS Process

• In a way, we are returning to days of old (i.e. DOS)…


other FCL
JIT Compiler – CLR applies a well-known search algorithm
assemblies
– customize search via .config (".ini") files
obj code Core FCL • For now, we'll assume simplified search algorithm:
obj code
obj code assembly – our DLLs must reside in same directory as our EXE
obj code

CLR – FCL assemblies reside in GAC


– CLR looks in GAC first, then EXE's directory…

Underlying OS and HW
23 24
GAC? Summary

• GAC = Global Assembly Cache • .NET architecture is:


– C:\Windows or C:\WinNT directory – multi-language
– cross-platform
– based on the CLR, FCL, and JIT technology
• Observations:
– explorer yields a flat view of GAC • Application designs are typically multi-tier
– command-shell yields actual representation • Application designs yield component-based development
– GAC can hold different versions of the same assembly – .NET components are packaged as assemblies
– some assemblies have been pre-JIT ("native image")
– tamper proof via digital signatures…

25 26

Recall assemblies

• 1 assembly = 1 or more compiled classes


– .EXE represents an assembly with classes + Main program
– .DLL represents an assembly with classes
Developing in .NET and C#
code.vb
code.vb
code.cs

Development Tools

.EXE / .DLL
assembly

28

.NET development Development options, cont'd

• There are currently 3 ways to develop assemblies: 2) Visual Studio .NET


• 5-6 CDs, 192 MB RAM (bare minimum)
1) .NET Framework SDK • powerful, integrated development environment (IDE)
• free (100 MB) • one IDE for all: GUI, web-based, web service, DLLs, etc.
• complete set of command-line tools and docs • this is what 99% of the world uses
• available for Windows NT, 2000, XP Pro, 2003 • $$
• http://msdn.microsoft.com/net – MSDNAA reduces cost to $800/year for unlimited access

• other platforms?
– FreeBSD / Mac OS X via Rotor (i.e. SSCLI) 3) free IDEs
– Linux via Mono project • #develop, a simplified clone of VS.NET
• WebMatrix, for building web-based applications

29 30
Hello World in C# Why System.Console prefix?

• Here's the source code: • In .NET, all code & data must live within a class
• Often nested within namespaces to help organize things
/* hello.cs */ – a namespace is really just a named collection

public class Startup


{ • Example:

public static void Main() System.Console.WriteLine("Hello World!");


{
System.Console.WriteLine("Hello World!");
} System
namespace
}//class in FCL
hello.cs Console
class

WriteLine
subroutine
31 32

Compiling and running Viewing an assembly with ILDasm

• To compile C# with Framework SDK, use the C# compiler • IL = Microsoft's Intermediate Language (i.e. generic asm)
– open Visual Studio .NET command prompt window to set path • ILDasm = IL Disassembler
– csc is the command-line C# compiler
– use /t:exe option to specify console-based EXE as target c:\> ildasm hello.exe

c:\> csc /t:exe hello.cs


Microsoft (R) Visual C# .NET Compiler version 7.00.9466
for Microsoft (R) .NET Framework version 1.0.3705
Copyright (C) Microsoft Corporation 2001. All rights reserved.

c:\> hello.exe
Hello World!

• To run, simply use name of assembly…

33 34

IL? Development on FreeBSD

• Very similar to Java bytecodes: • Working on FreeBSD is exactly the same!


– generic assembly language – i.e. same command-line tools as Framework SDK
– stack-based – produces *binary-compatible* .DLL and .EXE files!
– strictly typed
– no direct memory addressing
– verifiable for safe execution

35 36
Language options

• In .NET, the language really doesn't matter… • Class-based development…


– the standard languages all have essentially the same power
– now just a matter of preference

• Standard choices:
– VB.NET: fully-OOP, case-insensitive, friendly syntax
– C#: the equivalent of Java on the .NET platform
– J#: Java 1.4 syntax, Java 1.2 class library
– C++:
• managed mode: generates .NET assembly
• unmanaged mode: generates traditional Windows binary

37 38

A customer class Main class

• Here's the source code for a simple Customer class: • Here's the source code for Main, using our Customer class:

/* customer.cs */
/* main.cs */
public class Customer
{ public class App
public string Name; // fields {
public int ID;
public static void Main()
public Customer(string name, int id) // constructor {
{ Customer c;
this.Name = name; c = new Customer("joe hummel", 94652);
this.ID = id; System.Console.WriteLine( c.ToString() );
} }

public override string ToString() // method }//class


{
return "Customer: " + this.Name;
}
}//class
39 40

Compiling and running application

• Compile and run as before… • Component-based development…


– /out: option specifies name of resulting EXE
– in this case we are building monolithic app (single EXE, no DLLs)

c:\> csc /t:exe /out:app.exe main.cs customer.cs


Microsoft (R) Visual C# .NET Compiler version 7.00.9466
for Microsoft (R) .NET Framework version 1.0.3705
Copyright (C) Microsoft Corporation 2001. All rights reserved.

c:\> app.exe
Customer: joe hummel

41 42
Example Compiling a component

• Let's rebuild previous app based on components • Use the C# compiler…


– Customer class ==> DLL – with /t:library option to specify component library as target
– Main class ==> EXE – csc produces a DLL in this case

c:\> csc /t:library customer.cs


Microsoft (R) Visual C# .NET Compiler version 7.00.9466
main.cs customer.cs for Microsoft (R) .NET Framework version 1.0.3705
Copyright (C) Microsoft Corporation 2001. All rights reserved.

c:\> dir *.dll


app.exe + customer.dll customer.dll

43 44

Compiling and running application Where are references stored?

• Compile using C# compiler as before, except… • Within assembly as part of assembly manifest
– reference component so compiler can locate Customer class! • Visible via ILDasm
– reference also stored inside assembly so CLR can locate
c:\> ildasm app.exe
c:\> csc /t:exe /out:app.exe main.cs /r:customer.dll
Microsoft (R) Visual C# .NET Compiler version 7.00.9466
for Microsoft (R) .NET Framework version 1.0.3705
Copyright (C) Microsoft Corporation 2001. All rights reserved.

c:\> app.exe
Customer: joe hummel

• To run, use name of assembly containing Main…


– CLR follows reference to locate DLL

45 46

mscorlib? Recall CLR-based execution

• mscorlib = "ms-core-lib" • All assemblies must be present:


• Core FCL assembly .DLL
.EXE .DLL
– contains core system classes like string .DLL
– contains System.Console class for console-based I/O
OS Process

• Automatically referenced for us by C# compiler…


other FCL
JIT Compiler
assemblies

obj code Core FCL


obj code
obj code assembly
obj code

CLR

Underlying OS and HW
47 48
Summary Resources

• .NET is multi-language • Books:


– Framework SDK based on C# and VB.NET – J. Richter, "Applied Microsoft .NET Framework Programming" (C#)
– lots of other languages available – J. Richter and F. Balena, "Applied Microsoft .NET Framework
Programming in Microsoft Visual Basic .NET" (VB)
• .NET development is component-based – T. Thai and H. Lam, ".NET Framework Essentials"
– helper classes implemented in one or more DLLs
– EXE implemented using helper classes
– if (assembly A uses a class from assembly B)
then A must reference B!

49 50

References

• Web sites:
– http://msdn.microsoft.com/net
– http://www.gotdotnet.com/
– MSDNAA: http://www.msdnaa.net/
– Rotor (SSCLI): http://msdn.microsoft.com/net/sscli
– Mono: http://www.go-mono.com/
– Free IDEs:
• http://www.icsharpcode.net/OpenSource/SD/default.asp
• http://www.asp.net/webmatrix/
– Anakrino reverse-engineering tool:
• http://www.saurik.com/net/exemplar/

51

You might also like