Transcript Document

Java2C#
Antonio Cisternino
Part VI
Outline
Web services
 ASP.NET
 Framework SDK:

 Compilers
 Tools
…
Outline
 Web
services
ASP.NET
 Framework SDK:

 Compilers
 Tools
…
Distributed systems




In the past two decades programs have become
more and more distributed
A distributed system is composed by software
running on several computers that communicate
over a network
Such a system could be built using networking
primitives (i.e. sockets)
Another approach could be inserting network
communications into a language offering an
higher level of the distributed system that
abstracts from network communication details
Remote Procedure Calls






RPC is a standard to support invocation of procedures
across the network
A server is running on the host where the procedure will
be executed
A client invokes a local procedure whose signature is
equivalent to the remote one
The procedure is a stub that marshals parameters
across the network and waits for the return value
To optimize network usage the programmer could
annotate in/out parameters
The RPC standard is connection oriented and fragile (i.e.
windows SMB resources)
CORBA







CORBA is an OGM standard
It has been conceived to build flexible distributed
architectures
It is tied to IDL and C++, in particular original standards
don’t support metadata
CORBA is service oriented: no components!
The standard defines a protocol and the structure of a
broker that mediates communications among clients and
service providers
The broker introduces high degree of flexibility into the
model as well as lots of configuration issues
CORBA has been used to build big services in intranets
but it seems not scale well to the Internet
DCOM





DCOM is a distributed version of COM
It is really component based
In-process stubs allows communication of
distributed components
The communication protocol is open but really
complex: it is based on RPC and generates lots
of traffic to support distribute garbage collection
Configuration is difficult and registry based
Can we have Internet components?




Success of HTTP is tied to stateless nature of
the protocol: it scales well
Distributed systems tends to be stateful
With the advent of firewalls most TCP/IP ports
have been closed and HTTP is one of the few
services always accessible
Since 1997 many groups have worked to RPC
protocols based on HTTP and XML
W3C and SOAP




Among different alternatives the Web consortium
has chosen the SOAP protocol as the standard
for XML-Based RPC
SOAP: Simple/Sophisticated Object Access
Protocol
Together with SOAP XML schemas contribute to
face the problem of serializing structured data
types
SOAP is the core element of Web services
although the standard doesn’t depend on Web
Discovery of services: UDDI




When services becomes available world-wide
there must be an infrastructure to support their
discovery
Microsoft, IBM and other companies support
UDDI initiative
UDDI is a set of directories where companies
are allowed to publish their Web services
The directory is human browsable but it could be
also accessed programmatically
Inspecting a service




Once located only the URL of a service is known
A Web service is a method exposed through an
URL
The service’s interface is described in an XMLbased language called WSDL
WSDL expresses types involved into the
interface of the service and other information
related to it (i.e. the access method)
SOAP
SOAP is a message based protocol
 It defines format of messages that carries
structured data expressed in XML
 The protocol defines the structure of
envelopes and how it is routed on
transportation protocols
 Being message based could be routed on
stateless protocols such as HTTP and
SMTP

.NET and Web services





A framework supports web services if it bridges
automagically language’s semantic elements
into SOAP messages and vice-versa
.NET provides tools to handle with SOAP, WSDL
and related protocols
IIS comes with a module that allows exposing
method of .NET types as Web services
The programmer simply uses custom attributes
to control such module
Reflection allows automatic generation of
wrapping code
Demo
Outline

Web services
 ASP.NET

Framework SDK:
 Compilers
 Tools
…
Active Server Pages


ASP was the Microsoft technology for dynamic Web
The conceptual structure was easier:





Pages were mix of HTML and scripts executed on the server
The server generates a script from the page quoting HTML with
print instructions
Each request implies execution of the script whose result is the
HTML served to the client
ASP has been successful because it is easy and
powerful (thanks to COM!)
Drawback: web applications difficult to maintain because
of tangling of code and data
ASP.NET




ASP.NET tries to push forward ASP model
exploiting the .NET framework
In this case pages are .NET classes instead of
simple scripts
XML is used to separate presentation from
business logic
Code is exposed as “component” localized with
a tag into the page
Application as a whole




ASP.NET tries to simulate a desktop
programming environment
The Web application is a set of “forms” (web
pages) containing components that provide
behavior
Issue: real graphical elements are on the client
and the runtime tries to control them remotely
The model improves Web applications
development although the runtime cannot hide
all the details of underlying model: browser +
HTTP + Web Server
Outline
Web services
 ASP.NET

 Framework
 Compilers
 Tools
…
SDK:
Framework SDK
.NET runtime ships freely with the
Framework SDK (as Java and JDK)
 The SDK includes:

 The
runtime
 Documentation
 Compilers (Jscript, VB, C#, ilasm)
 Tools (al, gacutil, ngen, …)
C# compiler (csc)



C# compiler supports several options
The switch /? displays the list of options
The most useful switches are:








/out:filename
/t:{exe,winexe,library module}
/d:<Symbol list>
/recurse:<wildcard>
/reference:<assembly list>
/addmodule:<modules list>
/doc:<file>
/{res,linkres}:<resource>
Assemblies vs. Modules




One limit of big Java projects was the absence
of an external incremental compilation model
(i.e. make)
C# supports modules: assemblies without
assembly manifest
Modules are very like object C/C++ files
An assembly linker (al) supports assembly
generation from modules
Visual Basic and Jscript compilers

With Framework SDK are also shipped:
 Visual
Basic compiler (vbc)
 Jscript (ECMA-262) compiler (jsc)



Jscript is a scripting language that has been
extended with types and to be CLI compatible
Language extensions have been submitted for
standardization
Jscript allows mixing of interpreted and compiled
code and supports eval of code strings
ILasm & ILdasm

It is possible to define IL as a text file and use the ILAsm tool to compile it:
.namespace Test {
.class public auto ansi beforefieldinit TestClass
extends [mscorlib]System.Object {
.method public hidebysig static
void Main(string[] args) cil managed {
.entrypoint
.maxstack 0
IL_0000: ret }
.method public hidebysig static
int32 Add(int32 i, int32 j) cil managed {
.maxstack 2
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: add
IL_0007: ret }}}

The IlDasm allows reading Metadata and IL stored in assemblies
Assembly management

Assembly Cache Viewer (Shfusion.dll):
 Loaded




with %WinDir%\assembly
Assembly linker (Al.exe)
With Fuslogvw.exe it is possible to monitor
failures in loading assemblies
Gacutil.exe manages the global assembly cache
Ngen.exe controls the native image cache
.NET and COM
tlbimp: builds an assembly out of a set of
COM components that exposes them into
.NET
 Regasm.exe registers .NET assemblies
into registry exposing them as COM
components
 tlbexp: outputs a type-library for COM

Web Services XML and Remoting




Disco.exe inspects web services on a web
server
Wsdl.exe generate WSDL description of a web
service together with .discomap file
Xsd.exe helps generation of XML schemas
Soapsuds.exe supports Remoting applications
generating code that manages SOAP based
communication
Debugging & Development
Cordbg.exe is a command line debugger
like gdb
 DbgCLR.exe is a graphical debugger
 Resgen.exe compiles XML based
resource description into binary form
 WinCv.exe is a graphical class browser
 Winres.exe allows editing binary resources

Security






Makecert.exe generates X.509 certificates for testing purposes only.
Certmgr.exe manages certificates, certificate trust lists (CTLs), and
certificate revocation lists (CRLs)
Certificate Verification Tool (Chktrust.exe) verifies the validity of a file
signed with an X.509 certificate
Code Access Security Policy Tool (Caspol.exe) allows you to
examine and modify machine, user, and enterprise-level code
access security policies
Signcode.exe signs a portable executable (PE) file with an
Authenticode digital signature
Permissions View Tool (Permview.exe) displays the minimal,
optional, and refused permission sets requested by an assembly
Security





PEverify.exe performs MSIL type safety verification checks and
metadata validation checks on a specified assembly.
Secutil.exe extracts strong name public key information or
Authenticode publisher certificates from an assembly, in a format
that can be incorporated into code
Setreg.exe allows you to change the registry settings for the
Software Publishing State keys, which control the behavior of the
certificate verification process
Cert2spc.exe creates, for test purposes only, a Software Publisher's
Certificate (SPC) from one or more X.509 certificates
Strong Name Tool (Sn.exe) helps create assemblies with strong
names. Sn.exe provides options for key management, signature
generation, and signature verification