1 Corba Architecture Functions of ORB Communication between client - - PDF document

1
SMART_READER_LITE
LIVE PREVIEW

1 Corba Architecture Functions of ORB Communication between client - - PDF document

CS 242 Topic Interoperability Many systems built using multiple languages Fortran calls to C code, vice versa Microsoft: VBasic, C, C++ Communication between modules John Mitchell Function call with primitive-type arg and


slide-1
SLIDE 1

1

CS 242

Interoperability

John Mitchell

Topic

Many systems built using multiple languages

  • Fortran calls to C code, vice versa
  • Microsoft: VBasic, C, C++

Communication between modules

  • Function call with primitive-type arg and result?
  • Shared objects?
  • Error handling and exceptions?

Topic

Many systems built using multiple languages

  • Fortran calls to C code, vice versa
  • Microsoft: VBasic, C, C++

Communication between modules

  • Function call with primitive-type arg and result? Yes
  • Shared objects? Focus of this lecture
  • Error handling and exceptions? Still evolving

Three basic approaches

Client-Implementation Intermediary

  • Convert messages from one implementation to another
  • Example: Corba

Binary compatibility

  • Compatible values passed between implementations
  • Example: COM

Neutral platform

  • Run on multiple languages on virtual machine
  • Example: .Net

Background: some related issues

Dynamic linking

  • Update parts of a system independently

– C++: Link compiled code to stub – Stub contains code to interact with DLL

  • Share components among different applications

Implementation compatibility

  • Can C++ component compiled with one compiler be

dynamically linked with component from another?

Inter-language interoperability

  • Two languages ∼ two compilers

Corba Concept

Insert “broker” between client and server

CLIENT

ORB request ORB Result/ error

SERVER/OBJECT IMPLEMENTATION

slide-2
SLIDE 2

2

Client ORB Core IDL Stub ORB Interface IDL Skeleton Object Adapter Object Implementation

Corba Architecture Functions of ORB

Communication between client and server

  • Insulates application system configuration details

Specific steps

  • Intercepts calls
  • Finds object
  • Invokes method
  • Passes parameters
  • Returns results or error messages

Interface description language

  • IDL generates ‘stubs’ and ‘skeleton’ programs for each interface
  • ‘Stub’ acts like a local function call, providing interface to ORB
  • ‘Skeleton’ yields server side implementation of IDL interface

Client

IDL Stub ORB Interface IDL Skeleton Object Adapter Object Implementation

ORB Core Interface Description

CORBA application development

Write the IDL interface Map .idl file to target language (C++, Java, …)

  • IDL Compiler

Develop a Client application Develop the Server Compile and run the application

IDL Example

Hello.java

(IDL interface in Java)

_HelloStub.java

(client stub)

_HelloImplBase.java

(server skeleton)

HelloHelper.java

(auxiliary functionality)

HelloHolder.java

(delegates r/w methods)

Hello.idl

module HelloApp { interface Hello { string sayHello(); }; };

Interface translation

IDL Statement Java Statement

module HelloApp package HelloApp; interface Hello public interface Hello string sayHello(); String sayHello();

/* Hello.java as generated by idltojava */ package HelloApp; public interface Hello extends org.omg.CORBA.Object { String sayHello(); } module HelloApp { interface Hello { string sayHello(); }; };

slide-3
SLIDE 3

3 IDL Compiler Output

_HelloImplBase.java

  • Abstract class provides the server skeleton, basic CORBA functionality
  • Implements Hello.java interface
  • server class HelloServant extends _HelloImplBase

_HelloStub.java

  • Client stub, with CORBA functionality for the client
  • Implements Hello.java interface.

Hello.java

  • Interface containing Java version of IDL interface, extends
  • rg.omg.CORBA.Object

HelloHelper.java

  • Final class provides auxiliary functionality, including a narrow method

to cast CORBA object references to proper type

HelloHolder.java

  • Final class has public instance member of type Hello
  • Provides operations for out and in/out arguments, which CORBA

assumes but do not map immediately to Java

Implementing the Client

public class HelloClient { static Hello helloImpl; public static void main(String args[]) { try{ // create and initialize the ORB ORB orb = ORB.init(args, null); // get the root naming context

  • rg.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");

// Use NamingContextExt instead of NamingContext; part of Interoperable naming Service NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); // resolve the Object Reference in Naming String name = "Hello"; helloImpl = HelloHelper.narrow(ncRef.resolve_str(name)); System.out.println("Obtained a handle on server object: " + helloImpl); System.out.println(helloImpl.sayHello()); helloImpl.shutdown(); } catch (Exception e) { System.out.println("ERROR : " + e) ; e.printStackTrace(System.out); } } } import HelloApp.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; Just to give you some idea of what this looks like …

Hello World Architecture

Hardware Network TCP/IP LINUX Hardware TCP/IP Windows NT

(Hello.java) ORB (WNT)

HelloServer.java Server Skeleton

(_HelloImplBase.java)

Implementation Code (Hello Servant.java IDL Compiler IDL Compiler Interface Description in IDL (Hello.idl) Client Stubs

(_HelloStub.java)

ORB (LINUX) Application (Hello Client.java)

See http://java.sun.com/j2se/1.4.2/docs/guide/idl/jidlExample.html

Client

IDL Stub ORB Interface

ORB Core

ORB Interface IDL Skeleton Object Adapter

Implementation ORB Core

Internet Inter-ORB Protocol (IIOP)

Inter-ORB Communication

Corba ORB Architecture: more details

Corba Summary

Interface definition language (IDL)

  • Define interface in “neutral language”
  • Compiler generates several related files automatically

Object request broker (ORB)

  • System intermediary handles requests, response
slide-4
SLIDE 4

4 COM: Component Object Model

Purpose (marketing page)

  • “COM is used by developers to create re-usable

software components, link components together to build applications, and take advantage of Windows

  • services. …”

Current incarnations

  • COM+, Distributed COM (DCOM) , ActiveX Controls

References

  • Don Box, Essential COM
  • MS site: http://www.microsoft.com/com/

Central ideas in COM

Clients program using interfaces, not classes Implementation code is dynamically linked Manage requirements at run time

  • Object implementors declare runtime requirements
  • System ensures that these requirements are met

Evolution

  • Interfaces and dynamic linking are classic COM
  • Runtime requirements handled using Microsoft

Transaction Server (MTS) and COM+

Motivation

Build dynamically composable systems

  • Not all parts of application are statically linked

Independence of components

  • One change should not propagate to all source code
  • New components usable in place of old

Compatibility of components

  • Use components with different runtime requirements
  • Mix heterogeneous objects in a single process

Evolution in appreciation for abstraction

1980s: classes and objects

  • Classes used for object implementation
  • Classes also used for consumer/client type hierarchy

Dependencies between client and object

  • Client assumes complete knowledge of public interface
  • Client may know even more under certain languages

(C++)

1990s: separate interface from implementation

  • Client to program in terms of abstract types
  • Completely hides implementation class from client

Interface-Based Programming

Define interfaces for classes

  • C++ : use abstract base classes as interfaces

Associate implementations with interfaces

  • C++: inheritance

– Class FastString : public IFastString {...};

Create implementation objects without exposing layout

  • Usually a creator or factory function
  • Manipulate object indirectly through intermediate structure
  • Class unsuitable for declaring variables

– Want to avoid dependence on class

Client must be able delete object

  • Since new operator not used by the client, cannot call delete
  • Reference counting can be used

Interoperability

Use of interfaces separates implementation

  • Different implementations can coexist
  • These can be built in different languages
slide-5
SLIDE 5

5 Interfaces in different languages

Pure abstract base classes in C++

  • All methods are pure virtual
  • Never any code, only signature
  • Format of C++ vtable/vptr defines expected stack frame

Represented directly as interfaces in Java Represented as Non-Creatable classes in Visual Basic Uniform binary representation independent of how

  • bject is built

Identified uniquely by a 128-bit Interface ID (IID)

exter extern co n const nst IID IID exter extern co n const nst IID IID IID_ IID_IUnk IUnknow nown IID_ IID_IUnk IUnknow nown; ; struc struct struc struct IU IUnkn nknown

  • wn

IU IUnkn nknown

  • wn {

{ vir virtual tual HR HRESUL ESULT STD T STDMETH METHODC ODCALLT ALLTYPE YPE vir virtual tual HR HRESUL ESULT STD T STDMETH METHODC ODCALLT ALLTYPE YPE Query ueryInt Interfa erface ce Query ueryInt Interfa erface ce( ( con const I st IID& ID& con const I st IID& ID& rii riid rii riid, vo , void * id ** , vo , void * id **pp ppv pp ppv) = ) = 0; 0; ) = ) = 0; 0; vir virtual tual UL ULONG ONG STDME STDMETHOD THODCAL CALLTYP LTYPE E vir virtual tual UL ULONG ONG STDME STDMETHOD THODCAL CALLTYP LTYPE E Add AddRef Ref Add AddRef Ref( ) ) = 0; = 0; ( ) ) = 0; = 0; vir virtual tual UL ULONG ONG STDME STDMETHOD THODCAL CALLTYP LTYPE Rel E Release ease( ) ( ) = 0 = 0; vir virtual tual UL ULONG ONG STDME STDMETHOD THODCAL CALLTYP LTYPE Rel E Release ease( ) ( ) = 0 = 0; }; }; }; };

IUnknown

Three abstract operations (QueryInterface, AddRef, and Release) comprise the core interface of COM, IUnknown All COM interfaces must extend IUnknown All COM objects must implement IUnknown

IDL: generate Interfaces

COM interfaces may be defined in COM IDL IDL compiler generates C/C++ interface definitions

Foo.idl Foo.idl

IDL IDL Description Description

  • f
  • f Foo

Foo interfaces interfaces and datatypes and datatypes

Foo.h Foo.h

C/C++ C/C++ Definitions Definitions

Foo_i.c Foo_i.c

GUIDs GUIDs

Foo_p.c Foo_p.c

Proxy/Stub Proxy/Stub

dlldata.c dlldata.c

Class Loading Class Loading Support Support

Foo.tlb Foo.tlb

Binary Binary Descriptions Descriptions

MIDL.EXE MIDL.EXE

*.java *.java

Java Java Definitions Definitions

JACTIVEX.EXE JACTIVEX.EXE

COM IDL

COM interfaces may be defined in COM IDL IDL compiler generates C/C++ interface definitions

COM IDL

All elements in an IDL file can have attributes

  • Appear in [ ] prior to subject of attributes

Interfaces are defined at global scope

  • Required by MIDL to emit networking code

Must refer to exported types inside library block

  • Required by MIDL to emit type library definition

Can import std interface suite

– WTYPES.IDL - basic data types – UNKNWN.IDL - core type interfaces – OBJIDL.IDL - core infrastructure itfs – OLEIDL.IDL - OLE itfs – OAIDL.IDL - Automation itfs – OCIDL.IDL - ActiveX Control itfs

[ uuid(D [ uuid(DEFACED EFACED1 [ uuid(D [ uuid(DEFACED EFACED1-

  • 0229

0229 0229 0229-

  • 2552

2552 2552 2552-

  • 1D11

D11 1D11 D11-

  • AB

ABBADABBA BADABBAD00), object D00), object ] AB ABBADABBA BADABBAD00), object D00), object ] in interfac terface e in interfac terface e ICal ICalculator culator ICal ICalculator culator : : : : IDe IDesktopD sktopDevice evice IDe IDesktopD sktopDevice evice { { impo import “ rt “ impo import “ rt “dd dd.idl .idl dd dd.idl .idl”; ”; // bri // bring in ng in ”; ”; // bri // bring in ng in IDeskto IDesktopDevic pDevice IDeskto IDesktopDevic pDevice HRES HRESULT Cl ULT Clear(voi ear(void); d); HRES HRESULT Cl ULT Clear(voi ear(void); d); HRES HRESULT Ad ULT Add([in] d([in] short short n); n); // // n se n sent to nt to object

  • bject

HRES HRESULT Ad ULT Add([in] d([in] short short n); n); // // n se n sent to nt to object

  • bject

HRES HRESULT ULT HRES HRESULT ULT Ge GetSum([o tSum([out ut Ge GetSum([o tSum([out ut] sh ] short *

  • rt *

] sh ] short *

  • rt *pn

pn pn pn); // ); // * ); // ); // *pn pn pn pn se sent to nt to caller caller se sent to nt to caller caller } } [ [ [ [ uuid(D uuid(DEFACED EFACED2 uuid(D uuid(DEFACED EFACED2-

  • 0229

0229 0229 0229-

  • 2552

2552 2552 2552-

  • 1D11

D11 1D11 D11-

  • AB

ABBADABBA BADABBAD00), D00), AB ABBADABBA BADABBAD00), D00), helpst helpstring(“ ring(“My My helpst helpstring(“ ring(“My My Data Datatypes” types”) ) Data Datatypes” types”) ) ] ] li library brary li library brary CalcTy CalcTypes pes CalcTy CalcTypes pes { { import importlib(“s lib(“stdole32 tdole32.tlb”) .tlb”); // r ; // required equired import importlib(“s lib(“stdole32 tdole32.tlb”) .tlb”); // r ; // required equired interf interface ace interf interface ace IC ICalculat alculator

  • r

IC ICalculat alculator

  • r;

; // c // cause TL ause TLB incl B inclusion usion ; ; // c // cause TL ause TLB incl B inclusion usion } }

CalcTypes.idl CalcTypes.idl

COM IDL

slide-6
SLIDE 6

6 COM IDL - C++ Mapping

#i #include nclude “dd.h “dd.h” #i #include nclude “dd.h “dd.h” ex extern c tern const I

  • nst IID

ID ex extern c tern const I

  • nst IID

ID IID_ IID_ICalcu ICalculator lator IID_ IID_ICalcu ICalculator lator; ; st struct ruct st struct ruct __ __declsp declspec(uui ec(uuid(“DEFA d(“DEFACED1 CED1 __ __declsp declspec(uui ec(uuid(“DEFA d(“DEFACED1 CED1-

  • 0229

229 0229 229-

  • 25

2552 52 25 2552 52-

  • 1D11

1D11 1D11 1D11-

  • ABBAD

ABBADABBAD0 ABBAD00”)) 0”)) ABBAD ABBADABBAD0 ABBAD00”)) 0”)) IC ICalcula alculator tor IC ICalcula alculator tor : public : public : public : public IDeskt IDesktopDevi

  • pDevice

ce IDeskt IDesktopDevi

  • pDevice

ce { { virtu virtual HRE al HRESULT ST SULT STDMETHO DMETHODCALLT DCALLTYPE Cle YPE Clear(voi ar(void) = 0 d) = 0; virtu virtual HRE al HRESULT ST SULT STDMETHO DMETHODCALLT DCALLTYPE Cle YPE Clear(voi ar(void) = 0 d) = 0; virtu virtual HRE al HRESULT ST SULT STDMETHO DMETHODCALLT DCALLTYPE Add YPE Add(short (short n) = n) = 0; 0; virtu virtual HRE al HRESULT ST SULT STDMETHO DMETHODCALLT DCALLTYPE Add YPE Add(short (short n) = n) = 0; 0; virtu virtual HRE al HRESULT ST SULT STDMETHO DMETHODCALLT DCALLTYPE YPE virtu virtual HRE al HRESULT ST SULT STDMETHO DMETHODCALLT DCALLTYPE YPE Get GetSum(sh Sum(short

  • rt

Get GetSum(sh Sum(short

  • rt *

*pn pn pn pn) = 0; ) = 0; ) = 0; ) = 0; }; }; }; }; ex extern c tern const G

  • nst GUID

UID ex extern c tern const G

  • nst GUID

UID LIB LIBID_Cal ID_CalcTypes cTypes LIB LIBID_Cal ID_CalcTypes cTypes; ; co const II nst IID D co const II nst IID D IID_ IID_ICalcul ICalculator ator IID_ IID_ICalcul ICalculator ator = {0xDE {0xDEFACED1, FACED1, 0x022 0x0229, 0x2 9, 0x2552, 552, = {0xDE {0xDEFACED1, FACED1, 0x022 0x0229, 0x2 9, 0x2552, 552, { 0x1D, 0x1D, 0x11, 0x11, 0xAB, 0xAB, 0xBA, 0xBA, 0xDA, 0xDA, 0xBB, 0 0xBB, 0xAD, 0 xAD, 0x00 } x00 } }; }; { 0x1D, 0x1D, 0x11, 0x11, 0xAB, 0xAB, 0xBA, 0xBA, 0xDA, 0xDA, 0xBB, 0 0xBB, 0xAD, 0 xAD, 0x00 } x00 } }; }; co const GU nst GUID ID co const GU nst GUID ID LIB LIBID_Calc ID_CalcTypes Types LIB LIBID_Calc ID_CalcTypes Types = {0xD = {0xDEFACED2 EFACED2, 0x02 , 0x0229, 0x 29, 0x2552, 2552, = {0xD = {0xDEFACED2 EFACED2, 0x02 , 0x0229, 0x 29, 0x2552, 2552, { 0x1D, 0x1D, 0x11, 0x11, 0xAB, 0xAB, 0xBA, 0xBA, 0xDA, 0xDA, 0xBB, 0 0xBB, 0xAD, 0 xAD, 0x00 } x00 } }; }; { 0x1D, 0x1D, 0x11, 0x11, 0xAB, 0xAB, 0xBA, 0xBA, 0xDA, 0xDA, 0xBB, 0 0xBB, 0xAD, 0 xAD, 0x00 } x00 } }; };

CalcTypes.h CalcTypes.h CalcTypes_i.c CalcTypes_i.c

COM IDL – Java/VB Mapping

pa package ckage pa package ckage CalcTy CalcTypes pes CalcTy CalcTypes pes; // ; // libra library nam ry name ; // ; // libra library nam ry name /* /**@ *@ /* /**@ *@com. com.interf interface(iid ace(iid com. com.interf interface(iid ace(iid=DEFAC =DEFACED1 ED1 =DEFAC =DEFACED1 ED1-

  • 02

0229 29 02 0229 29-

  • 2552

2552 2552 2552-

  • 1D11

1D11 1D11 1D11-

  • ABBADA

ABBADABBAD00) BBAD00)*/ */ ABBADA ABBADABBAD00) BBAD00)*/ */ in interfac terface e in interfac terface e ICal ICalculator culator ICal ICalculator culator exten extends ds exten extends ds IDe IDesktopDe sktopDevice vice IDe IDesktopDe sktopDevice vice { { publ public voi ic void Clear d Clear( ); ( ); publ public voi ic void Clear d Clear( ); ( ); publ public voi ic void Add(s d Add(short n hort n); publ public voi ic void Add(s d Add(short n hort n); publ public voi ic void d publ public voi ic void d GetSu GetSum(shor m(short GetSu GetSum(shor m(short [] [] [] [] pn pn pn pn); // ); // array array of len

  • f length 1

gth 1 ); // ); // array array of len

  • f length 1

gth 1 publ public sta ic static tic publ public sta ic static tic com com.ms.co .ms.com._Gui m._Guid com com.ms.co .ms.com._Gui m._Guid iid iid iid iid = = ne new com. w com.ms.com. ms.com._Guid( _Guid(0xDEFA 0xDEFACED1, 0 CED1, 0x0229, x0229, 0x255 0x2552, 2, ne new com. w com.ms.com. ms.com._Guid( _Guid(0xDEFA 0xDEFACED1, 0 CED1, 0x0229, x0229, 0x255 0x2552, 2, 0x1D, 0x1D, 0x11, 0 0x11, 0xAB, 0 xAB, 0xBA, xBA, 0x1D, 0x1D, 0x11, 0 0x11, 0xAB, 0 xAB, 0xBA, xBA, 0xDA, 0xDA, 0xBB, 0 0xBB, 0xAD, 0 xAD, 0x00); x00); 0xDA, 0xDA, 0xBB, 0 0xBB, 0xAD, 0 xAD, 0x00); x00); } }

CalcTypes.java CalcTypes.java

Pu Public S blic Sub Cle ub Clear( ) ar( ) Pu Public S blic Sub Cle ub Clear( ) ar( ) Pu Public S blic Sub ub Pu Public S blic Sub ub Add Add(ByVal (ByVal Add Add(ByVal (ByVal n As I n As Integer nteger) n As I n As Integer nteger) Pu Public S blic Sub ub Pu Public S blic Sub ub Get GetSum(ByR Sum(ByRef ef Get GetSum(ByR Sum(ByRef ef pn pn pn pn As Int As Integer) eger) As Int As Integer) eger)

CalcTypes.cls CalcTypes.cls particular value particular value res res

Severity (31) Severity (31) Facility (27 Facility (27-

  • 16)

16) Code (15 Code (15-

  • 0)

0) 0 -

  • > Success

> Success 1 1 -

  • > Failure

> Failure FACILITY_NULL FACILITY_NULL FACILITY_ITF FACILITY_ITF FACILITY_STORAGE FACILITY_STORAGE FACILITY_DISPATCH FACILITY_DISPATCH FACILITY_WINDOWS FACILITY_WINDOWS FACILITY_RPC FACILITY_RPC

COM And Error Handling

COM (today) doesn’t support typed C++ or Java-style exceptions All (remotable) methods must return a standard 32-bit error code called an HRESULT

  • Mapped to exception in higher-level languages
  • Overloaded to indicate invocation errors from proxies

small small long long hyper hyper IDL IDL C++ C++ Java Java short short char char long long __int64 __int64 byte byte int int long long short short short short Visual Basic Visual Basic N/A N/A Long Long N/A N/A Integer Integer unsigned small unsigned small unsigned long unsigned long unsigned hyper unsigned hyper unsigned short unsigned short unsigned char unsigned char unsigned long unsigned long unsigned __int64 unsigned __int64 byte byte int int long long unsigned short unsigned short short short Byte Byte N/A N/A N/A N/A N/A N/A float float double double float float double double float float double double Single Single Double Double char char unsigned char unsigned char char char unsigned char unsigned char char char byte byte N/A N/A Byte Byte wchar_t wchar_t wchar_t wchar_t char char Integer Integer Script Script No No Yes Yes No No Yes Yes No No No No No No No No Yes Yes Yes Yes No No Yes Yes No No

COM Data Types

byte byte boolean boolean VARIANT_BOOL VARIANT_BOOL IDL IDL C++ C++ Java Java BYTE BYTE unsigned char unsigned char long long VARIANT_BOOL VARIANT_BOOL char char int int boolean boolean unsigned char unsigned char byte byte Visual Basic Visual Basic N/A N/A Long Long Boolean Boolean Byte Byte BSTR BSTR VARIANT VARIANT BSTR BSTR java.lang.String java.lang.String VARIANT VARIANT com.ms.com.Variant com.ms.com.Variant String String Variant Variant CY CY long long int int Currency Currency DATE DATE enum enum double double double double enum enum int int Date Date Enum Enum Typed Typed ObjRef ObjRef IFoo IFoo * * interface interface IFoo IFoo IFoo IFoo struct struct struct struct final class final class Type Type union union C C-

  • style Array

style Array union union N/A N/A array array array array N/A N/A N/A N/A Script Script No No No No Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No No No No No No

COM Data Types Reference counting

Leverage indirection through reference object

  • Clients “Delete” each reference, not each object

Object checks references to it

  • Objects track number of references and auto-delete

when count reaches zero

  • Requires 100% compliance with ref. counting rules

Client obligations

  • All operations that return interface pointers must

increment the interface pointer’s reference count

  • Clients must inform object that a particular interface

pointer has been destroyed

slide-7
SLIDE 7

7 COM Summary

Clients program using abstract data types: interfaces Clients can load method code dynamically without concern for C++ compiler incompatibilities Clients interrogate objects for extended functionality via RTTI-like constructs Clients notify objects when references are duplicated or destroyed Supports multi-language programming

.NET Framework

Microsoft cross-language platform

  • Many languages can use and extend .NET Framework

– Compile language to MSIL

  • All languages are interoperable

Focus on security and trust

  • Building, deploy and run semi-trusted applications

Two key components

  • Common Language Runtime
  • .NET Framework Class Library

Slide credit: Graphics, etc. stolen from MS slides on web

Current .NET Languages

C++ Visual Basic C# Jscript J# Perl Python Fortran COBOL Eiffel Haskell

  • SmallTalk
  • Oberon
  • Scheme
  • Mercury
  • Oz
  • RPG
  • Ada
  • APL
  • Pascal
  • ML

Language Examples

J# J#

String s String s = "authors"; = "authors"; SqlComma SqlCommand nd cmd cmd = new SqlComma = new SqlCommand("select nd("select * from "+s * from "+s, sqlconn); , sqlconn); cmd.Exec cmd.ExecuteReader(); uteReader();

Di Dim s as m s as Strin String s = s = "aut "authors" hors" Di Dim cmd m cmd As New As New SqlCom SqlCommand(" mand("select select * from * from " & s " & s, sqlc sqlconn)

  • nn)

cm cmd.Exec d.ExecuteRea uteReader() der()

VB.NET VB.NET

st string s ring s = "au = "authors"; thors"; Sq SqlComma lCommand nd cmd cmd = new = new SqlCom SqlCommand(" mand("select select * from * from "+s, "+s, sqlconn sqlconn); ); cm cmd.Exec d.ExecuteRea uteReader(); der();

C# C#

Language Examples

C++ C++

Stri String *s = ng *s = S"au "authors hors"; "; SqlC SqlComm

  • mmand

and cm cmd = new new SqlC SqlComm

  • mmand

and(St (Strin ring::Co ::Conca ncat(S t(S"se "selec lect * f from rom ", ", s) s), , sqlc qlconn

  • nn);

); cmd. cmd.Exe Execut cuteRe eReade ader(); ();

St String * ring *s = S" = S"authors authors"; "; Sq SqlComma lCommand nd cmd cmd = new = new SqlCom SqlCommand(S mand(String:: tring::Concat Concat(S"sel (S"select ect * * fr from ",

  • m ", s), sq

s), sqlconn); lconn); cm cmd.Exec d.ExecuteRea uteReader(); der();

Perl Perl

s = s = "aut "authors" hors" cm cmd =Sql =SqlComman Command("sele d("select ct * f * from " rom " + s, sq + s, sqlconn) lconn) cm cmd.Exec d.ExecuteRea uteReader() der()

Python Python

va var s = = "autho "authors" rs" va var cmd cmd = new = new SqlComm SqlCommand("s and("select elect * from * from " + s, " + s, sqlco sqlconn) nn) cm cmd.Exec d.ExecuteRea uteReader() der()

JScript JScript

Language Examples

slide-8
SLIDE 8

8

ENVIRONMENT DIVISION. ENVIRONMENT DIVISION. CONFIGURATION SECTION. CONFIGURATION SECTION. REPOSITORY. REPOSITORY. CLASS SqlCommand CLASS SqlCommand AS "System.Data.SqlClient.SqlCommand" AS "System.Data.SqlClient.SqlCommand" CLASS SqlConnection CLASS SqlConnection AS "System.Data.SqlClient.SqlConnection". AS "System.Data.SqlClient.SqlConnection". DATA DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. WORKING-STORAGE SECTION. 01 str 01 str PIC X(50). PIC X(50). 01 cmd-string PIC X(50). 01 cmd-string PIC X(50). 01 cmd 01 cmd OBJECT REFERENCE SqlCommand. OBJECT REFERENCE SqlCommand. 01 sqlconn 01 sqlconn OBJECT REFERENCE SqlConnection. OBJECT REFERENCE SqlConnection. PROCEDURE DIVISION. PROCEDURE DIVISION. *> Establish the SQL connection here somewhere. *> Establish the SQL connection here somewhere. MOVE "authors" TO str. MOVE "authors" TO str. STRING "select * from " DELIMITED BY SIZE, STRING "select * from " DELIMITED BY SIZE, str str DELIMITED BY " " INTO cmd-string. DELIMITED BY " " INTO cmd-string. INVOKE SqlCommand INVOKE SqlCommand "NEW" USING BY VALUE cmd-string sqlconn "NEW" USING BY VALUE cmd-string sqlconn RETURNING cmd. RETURNING cmd. INVOKE cmd INVOKE cmd "ExecuteReader". "ExecuteReader".

Cobol Cobol

Language Example

assembly_external(name="System.Data.SqlClient.SqlCommand") sqlcmdcharacter*10 xsqlcmd Cmd x='authors' cmd = sqlcmd("select * from "//x, sqlconn) call cmd.ExecuteReader() end

Fortran Fortran

DclFld MyInstObj Type( System.Data.SqlClient.SqlCommand ) DclFld s Type( *string ) s = "authors" MyInstObj = New System.Data.SqlClient.SqlCommand("select * from "+s, sqlconn) MyInstObj.ExecuteReader()

RPG RPG

Language Examples

(let* ( (s "authors") (cmd (new-SqlCommand (string-append "select * from " s) sqlconn))) (execute-command cmd))

Scheme Scheme

local s: STRING cmd: SQLCOMMAND do s := "authors" create cmd("select * from " + s, sqlconn) cmd.ExecuteReader() end

Eiffel Eiffel

Language Examples

Framework Architecture

Win32 Win32

MSMQ MSMQ (Message (Message Queuing) Queuing) COM+ COM+ (Transactions, Partitions, (Transactions, Partitions, Object Pooling) Object Pooling) IIS IIS WMI WMI

Common Language Runtime Common Language Runtime Base Framework Base Framework ADO.NET: Data and XML ADO.NET: Data and XML Web Services Web Services User Interface User Interface VB VB C++ C++ C# C# ASP.NET ASP.NET Perl Perl Python Python … …

Compiler Compiler Assembly Assembly

Common Language Runtime

DEVELOPMENT DEVELOPMENT

C# C# J# J# VB VB Cobol Cobol … … MSIL MSIL Metadata Metadata Resources Resources

pub public s c stat atic v void M Main(String[] ar args gs ) { S String us ng usr; F FileStream eam f; S Stream eamWriter er w; tr try { { us usr=Environm
  • nment.GetEnv
nvironment entVariab able("USERNAME") ; f=new new F FileStream eam(“C:\\tes est.txt",FileM eMod
  • de.Create);
w=new new S Stream eamWriter er(f); w.WriteLi eLine(usr); w.Clos
  • se(
e(); } cat catch ( ch (Exc xcept eption e
  • n e){
Cons
  • nsole.WriteL
eLine( ne("Except ception:"+e.ToString()); } } pub public s c stat atic v void M Main(String[] ar args gs ) { S String us ng usr; F FileStream eam f; S Stream eamWriter er w; tr try { { us usr=Environm
  • nment.GetEnv
nvironment entVariab able("USERNAME") ; f=new new F FileStream eam(“C:\\tes est.txt",FileM eMod
  • de.Create);
w=new new S Stream eamWriter er(f); w.WriteLi eLine(usr); w.Clos
  • se(
e(); } cat catch ( ch (Exc xcept eption e
  • n e){
Cons
  • nsole.WriteL
eLine( ne("Except ception:"+e.ToString()); } }

Source code Source code

Compiler Compiler Assembly Assembly

DEVELOPMENT DEVELOPMENT

C# C# J# J# VB VB Cobol Cobol … … MSIL MSIL Metadata Metadata Resources Resources

pub public s c stat atic v void M Main(String ng[] ar args gs ) { S String us ng usr; F FileStream eam f; S Stream eamWriter er w; tr try { { us usr=Environm nment.GetEnv nvironment entVariab able("USERNAME") ; f=new new F FileStream eam(“C:\\tes est.txt",FileM eMod
  • de.Create);
w=new new S Stream eamWriter er(f); w.WriteLi eLine(usr); w.Clos
  • se(
e(); } cat catch ( ch (Exc xcept eption e n e){ Cons
  • nsole.WriteL
eLine( ne("Except ception:"+e.ToString()); } } pub public s c stat atic v void M Main(String[] ar args gs ) { S String us ng usr; F FileStream am f; S Stream eamWriter er w; tr try { { us usr=Environm
  • nment.GetEnv
nvironment entVariab able("USERNAME") ; f=new new F FileStream eam(“C:\\tes est.txt",FileM eMod
  • de.Create);
w=new new S Stream eamWriter er(f); w.WriteLi eLine(usr); w. w.Close(); } cat catch ( ch (Exc xcept eption e
  • n e){
Consol
  • le.
e.WriteLine("Exc xception: n:"+e. e.ToString ng()); } }

Source code Source code

Application Application Directory Directory Global Global Assembly Assembly Cache (GAC) Cache (GAC)

Common Language Runtime

Assembly Assembly

DEVELOPMENT DEVELOPMENT DEPLOYMENT DEPLOYMENT

Setup Setup Copy Copy Browser Browser

Download Download Cache Cache Install Install

slide-9
SLIDE 9

9

Debug Engine Debug Engine JIT Compiler JIT Compiler & Verification & Verification Application Application Directory Directory

Setup Setup Copy Copy Browser Browser

Download Download Cache Cache Global Global Assembly Assembly Cache (GAC) Cache (GAC) Assembly Assembly

  • n Target
  • n Target

Machine Machine

Common Language Runtime

Assembly Assembly

DEVELOPMENT DEVELOPMENT DEPLOYMENT DEPLOYMENT

Install Install

EXECUTION EXECUTION

Assembly Assembly Loader Loader Policy Policy Manager Manager Class Class Loader Loader Native .exe Native .exe + GC table + GC table Code Code Manager Manager Garbage Collection Garbage Collection Exception Manager Exception Manager Thread Support Thread Support Security Permission Security Permission Enforcement Enforcement

Policy

<?xm xml v version= n="1.0" en encod coding= g="utf-8" ? ?> <conf configur urat ation> n> <mscor corlib> <secur ecurity> <p <policy> <PolicyLevel el version= n="1"> <CodeG deGroup clas ass="Union
  • nCode
  • deGroup"
  • up"
version=
  • n="1"
PermissionSetNam ame= e="Not
  • thing"
ng" Na Name="All_Code" Descript ption=
  • n="Cod
  • de gr
e group
  • up
gr grant ants no per no permissio ns ns and f and forms t the r e root
  • t of
  • f t
the c e code
  • de gr
group t
  • up tree.">
<IMember bershipCond
  • ndition clas
s="AllMembership ipCondit itio ion" version=
  • n="1"/>
<Cod
  • deG
eGroup up clas ass="UnionC
  • nCodeG
deGroup" up" version="1 "1" PermissionS
  • nSet
etName="Fu FullTrus ust"

Security Issues

OS security is based on user rights CLR security, added on top of OS security, gives rights to code

Trusted user Trusted user Trusted code Trusted code Untrusted user Untrusted user Untrusted code Untrusted code Trusted user Trusted user Untrusted code Untrusted code Untrusted user Untrusted user Trusted code Trusted code

! ! ! !

.NET Summary

Compile multiple languages to common intermediate language (MSIL) MSIL executed by virtual machine

  • Similar to Java VM in many respects
  • More elaborate security model
  • JIT is standard, instead of interpreter

MSIL contains special provisions for certain languages

Summary

CORBA

  • Interoperability through programming conventions,

ORB intermediary

COM

  • Conventions for producing binary-compatible objects
  • Client uses interface only, no knowledge of object

format

.NET

  • Compile multiple language to single MSIL
  • MSIL handles dynamic linking/loading, security, …

– “managed” and “unmanaged” code