Listing 21 Output from Ildasmexe that shows metadata for Hello DotNetexe

ScopeName : HelloDotNet.exe

ScopeName : HelloDotNet.exe

MVID : {D9382B73-AF72-4778-8184-38EEA6400342}

Global functions

Global fields

Global MemberRefs

TypeDef #1

TypDefName: modmain (02000002)

Flags : [Public] [AutoLayout] [Class] [Sealed] [AnsiClass] (00000101) Extends : 01000001 [TypeRef] System.Object Method #1 [ENTRYPOINT]

MethodName: Main (06000001)

Flags : [Public] [Static] [ReuseSlot] (00000016)

RVA :0x00002050

ImplFlags : [IL] [Managed] (00000000)

CallCnvntn: [DEFAULT]

ReturnType: Void

No arguments.

CustomAttribute #1 (0c000001)

CustomAttribute Type: 0a000003 CustomAttributeName: System.STAThreadAttribute ::

instance void .ctor() Length: 4

ctor args: () CustomAttribute #1 (0c000002)

CustomAttribute Type: 0a000002 CustomAttributeName:


Token: 0x01000001

ResolutionScope: 0x23000001 TypeRefName: System.Object

TypeRef #2 (01000002)

Token: 0x01000002

ResolutionScope: 0x23000001 TypeRefName: System.Console MemberRef #1

Member: (0a000001) WriteLine: CallCnvntn: [DEFAULT] ReturnType: Void 1 Arguments Argument #1: String

TypeRef #3 (01000003)

Token: 0x01000003

ResolutionScope: 0x23000002 TypeRefName:

Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute MemberRef #1

Member: (0a000002) .ctor: CallCnvntn: [DEFAULT] hasThis

ReturnType: Void No arguments.

TypeRef #4 (01000004)

Token: 0x01000004

ResolutionScope: 0x23000001 TypeRefName: System.STAThreadAttribute MemberRef #1

Member: (0a000003) .ctor: CallCnvntn: [DEFAULT] hasThis

ReturnType: Void No arguments.


Token: 0x20000001 Name : HelloDotNet Public Key :

Hash Algorithm : 0x00008004

Major Version: 0x00000000 Minor Version: 0x00000000 Build Number: 0x00000000 Revision Number: 0x00000000 Locale: <null>

Flags : [SideBySideCompatible] (00000000) AssemblyRef #1

Token: 0x23000001

Public Key or Token: b7 7a 5c 56 19 34 e0 89

Name: mscorlib

Major Version: 0x00000001

Minor Version: 0x00000000

Build Number: 0x00000c1e

Revision Number: 0x00000000

Locale: <null>

HashValue Blob:

Flags: [none] (00000000)

AssemblyRef #2

Token: 0x23000002

Public Key or Token: b0 3f 5f 7f 11 d5 0a 3a

Name: Microsoft.VisualBasic

Major Version: 0x00000007

Minor Version: 0x00000000

Build Number: 0x00000000

Revision Number: 0x00000000

Locale: <null>

HashValue Blob: Flags: [none] (00000000)

User Strings

The first thing you'll notice is that the metadata contains lots of information. The metadata is organized into tables, which essentially describe what your code defines and references. For example, TypeDef #1 is a definition table that includes information about the Main procedure that is defined in the code. In the TypeDef #1 table, you can see that the Main procedure doesn't return a value (ReturnType: Void) and doesn't take any arguments (No arguments). TypeRef #2 is a reference table that includes information about the .NET Framework System.Console class that is referenced in the code. The TypeDef #2 table references the WriteLine method, which doesn't return a value and takes one argument of type String. The metadata can also include name and version information, referenced files and assemblies, security permissions, and other information.

You might be asking yourself, Why is all this metadata needed? One reason is that it provides a language-independent description of the code. Another reason is that it makes your assembly self-describing and enables other environments to discover functionality about your assembly. An assembly is one or more files that can be logically grouped and deployed. HelloDotNet.exe is actually a single file assembly. I'll talk more about assemblies in Chapter 6. When designing Web services, the metadata can be used to create a WSDL (Web services Description Language) file, which can be used to discover information exposed by the service. You'll learn more about Web services in Chapter 10, but briefly a Web service is a software component or service that is exposed over the Web. To give you a sneak preview, Figure 2-3 shows a Web page automatically generated by pointing to an ASP.NET page designed as a Web service.


'Jfl ¿-:k ¡to* [KM ;«<

>6*!. » J J -2 djlwi Jfr^l £«fAl J -J,' J J

ltd h-T . fc-f r.-»:• TÎ ■ fcHTtn^H,afrmw*-,r*. m, tx

Ma thService


- 'or s i ci« L n ■!* Bovats^i

Tail f4MM IHfril" B4 HTT» L^r^vJ. r»4 WW-PéTMMfliri i 1 1

In I >1


it li U iv'rfv

Figure 2-3 : A Web page automatically generated from a Web service

As you can see, the Web service being run has an Add method that, not surprisingly, expects two parameters. Type 2 in each of the Value boxes, and click Invoke. The result is returned as an XML result set, as shown in Figure 24. I'll cover XML and data access in general in Chapter 8.

0» 4* 14* ft*

■* ¿Swri) jfratm .r/Hrti J -

Iti tax I *>■> mm

.m -

cftHfl ■ ■




Figure 2-4 : The result screen that appears when you invoke the Add method in Figure 2-3

The information gathered from examining the metadata lets potential users discover the required parameters and test the Web service without constructing any test frames. This capability will become increasingly important as Web services become the default method for exposing functionality over the Web.

Note In general, the ability to discover the details of code created based on the .NET Framework is beneficial. However, developers who are distributing binary code to run on client workstations rather than creating Web pages and Web services might not consider this capability an asset. As of this writing, there's no supported way to suppress this information, although in theory there's nothing to prevent the obfuscation of the information. For example, you could rename a method named GetSecretCode with a nonsense name such as DDFeewsayppfgeEk to change its visibility without compromising the runtime's ability to look at the code as required for security checks. This sort of obfuscation is used to conceal client-side JScript code as well as C language code that needs to be distributed in source code form. Fortunately, developers creating ASP.NET applications don't usually need to be concerned with this issue.

Was this article helpful?

0 0

Post a comment