1 / 30

Additional .NET Concepts

Additional .NET Concepts. Daragh Byrne – EPCC. Purpose. Web Services using ASP.NET Basis of MS.NETGrid software Assemblies Metadata and reflection Application configuration. ASP.NET and Web Services. ASP.NET Features. Unified Web Development Platform

shika
Download Presentation

Additional .NET Concepts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Additional .NET Concepts Daragh Byrne – EPCC

  2. Purpose • Web Services using ASP.NET • Basis of MS.NETGrid software • Assemblies • Metadata and reflection • Application configuration

  3. ASP.NET and Web Services

  4. ASP.NET Features • Unified Web Development Platform • Runs under Microsoft Internet Information Services (IIS): • Available on all Windows Platforms better than Win2K • Requires .NET runtime (CLR) • Combines traditional forms-based Web Application development and Web Services • Runs compiled applications so performs better than traditional ASP • Excellent support in Visual Studio .NET • WYSIWYG-based design like designing Windows Forms

  5. Reference • Material from this lecture covered in great detail in your “Building Web Services” book: • Chapter 6 in particular

  6. Web Applications in ASP.NET • The files present in a virtual directory under IIS comprise a Web Application: • Isolated application domain for each Web application • Can contain both Web pages and Web Services • Lives in own AppDomain: • Memory protected region within a process, a .NET feature • Protects applications from one another • Requests for a page/service are mapped by IIS to the ASP.NET handler: • aspnet_isapi.dll, aspnet_wp.exe • Listen for file extensions .aspx, .asmx etc • Work carried out by a recycled process for efficiency and stability • Configuration is handled by Web.config in the root directory: • Web.config is standard ASP.NET application configuration file

  7. Request Handling Request IIS (aspnet_isapi.dll) Response Response asmx handler aspx handler

  8. Web Pages in ASP.NET • HTML lives in .aspx files: • Code can be placed here, or • Code in separate file • Presentation layer separated from logic: • A step away from the ugly embedded ASP model • Supports Web controls: • Reusable UI elements, e.g. menus, date-pickers • Can write custom controls • More details available in .NET framework documentation: • We concentrate on the Web Services aspect

  9. ASP.NET Request Handling foo.aspx HTTP request to foo.aspx HTTP Response to client ASP.NET Output (html) Compile and execute

  10. Web Services in ASP.NET • Write a class that provides the service functionality: • Tag operations with WebMethod attribute • Tag class with WebService attribute to specify default namespace of the service • Write a .asmx file: • References the implementing class • Can separate .asmx file and source code

  11. Web Service Request Handling Foo.asmx SOAP request to foo.asmx SOAP Response to client ASP.NET Output (SOAP) Execute

  12. Example Web Service // HelloService.asmx <% WebService Class=“HelloService” %> .. .. .. // HelloService.cs [WebService( NameSpace=“http://myURL.com/HelloService” )] public class HelloService {[WebMethod]public string SayHello(string name){ return “Hello there, “ + name);} } • Compile and deploy under ASP.NET: • Easiest with Visual Studio .NET • Build a client

  13. Useful Attributes • WebServiceAttribute • BufferResponse • Description • MessageName • Can use WebServiceAttributeto set properties of the service: • [WebService( Namespace=“someURI”, Description=“Some text describing the service”)]

  14. Automatic WSDL Generation • ASP.NET will automatically generate WSDL service descriptions • Send WSDL on the query string to see this: • e.g. service at http://localhost/myservice.asmx?WSDL • Reflection on service type to generate this document: • Uses e.g. WebMethod attributes to generate operation elements • Can control contents of WSDL document with attributes: • e.g. SoapDocumentMethodAttribute • Can suppress WSDL generation and do custom generation

  15. Building Web Service Clients • Idea is that accessing a Web Service is as simple as making method call • Use the WSDL description to auto-generate client ‘proxy’ classes • .NET Framework provides wsdl.exe tool: • wsdl http://myhost.com/SomeService.asmx?wsdl /o:ServiceProxy.dll • Examines a WSDL document • Outputs a DLL with a class that represents the service: • Derived from SoapHttpClientProtocol class, which handles serialization, invocation, etc • Highly integrated with Visual Studio.NET: • Does wsdl.exe behind the scenes, adds proxy stub to project automatically

  16. Web Services Enhancements • SDK to support emerging W3C Web Services protocols that address: • Security (WS-Security) • Policy • Routing • Custom SOAP Attachments • Reliable messaging • Now at version 2.0: • http://msdn.microsoft.com/webservices/building/wse/

  17. Assemblies

  18. Assemblies • Assemblies are the unit of code distribution in .NET • May be independently versioned • May be digitally signed • Scope the types within them • Are the basis of Code Access Security: • Code from an assembly can do certain things based on level of trust of assembly provider

  19. Working with Assemblies • Logical assembly consists of a number of modules (files): • Primary module references the other modules • Primary module identifies assembly • Most cases only one module • Assemblies contain code, data and/or resources: • e.g icon byte streams. • Assemblies scope the types and data within them: • public, private, internal(package level in Java) modifiers apply to types at assembly level • Same type defined in different assemblies == different types • Assembly names are resolved by the runtime before loading: • Must reside in APPBASE or subdirectory: • APPBASE is standard location off application directory, usually /bin • APPBASE can be changed using configuration files

  20. Assembly Identification • Assemblies may be strongly-named or weakly-named: • Weakly-named just identified by the name of the primary module, minus the .dll or .exe • Strongly-named have version, culture, public key as well • Concurrent versions of an assembly stored in the Global Assembly Cache: • Can only store strongly-named • Can specify dependence of application on particular assembly in configuration file

  21. Dynamic Assembly Loading • Can work with Assemblies programmatically: • Members on the System.Reflection.Assembly class • Assembly.Load • Assembly.LoadFrom • Assembly.CreateInstance(string typeName) • Assembly.GetCustomAttributes() • Important to know about assemblies for our OGSI implementation

  22. Using Metadata

  23. Attributes • Attributes allow you to add metadata to your types: • Enables a declarative style of programming • Can use framework-supplied or custom attributes • Information from attributes are stored in metadata for that type • Example: public class MyClass{ [System.Obsolete(“Will be removed next release”)] public void SomeObsoleteMethod() { }}

  24. Common Attribute Uses • Conditional compilation/calling: [Conditional(“DEBUG”)]public void myDebugMethod(string s) {} • XML serialisation: [XmlElement(“name”, someNameSpace)public string name_; • Web Service operations: [WebMethod]public string MyWebMethod(){ }

  25. Custom Attributes • Can define own attribute: • Inherit from System.Attribute • Define usage using – you guessed it – an attribute! • Example: [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]public class SomeUsefulAttribute: System.Attribute{ public SomeUsefulAttribute(string s) { }}// Use like[SomeUseful(“Hello”)]public class SomeClass{}

  26. The Reflection API • Can get access to your attributes using this API: public void SomeCode(){ object [] customAttributes = someObject.GetType().GetCustomAttributes( typeof(SomeUsefulAttribute)); foreach(SomeUsefulAttribute attr in customAttributes) { //process } } • Can get attributes on methods, fields, etc in a similar manner: • See the .NET documentation for System.Reflection namespace

  27. Application Configuration

  28. Application Configuration • Previously ad-hoc, comma-separated value files, language-specific etc: • Lots of different standards • .NET aims to provide consistent configuration for every application: • XML file-based • XML file in same directory as application usually • System.Configuration namespace provides API for doing this: • Extensible to use your own configuration schema • Web applications use the Web.config file as default

  29. Example Configuration File <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <sectionGroup name="gridContainer.config"> <section name="containerProperties“ type=“HandlerType"/> <section name="gridServiceDeployment“ type=“HandlerType"/> </sectionGroup> </configSections> <system.web> <!- - Web Application Configuration - - > </system.web> <system.runtime.remoting /> <gridContainer.config> <containerProperties> ... </containerProperties> <gridServiceDeployment> ... </gridServiceDeployment> </gridContainer.config> </configuration>

  30. Other .NET Topics of Interest • Win32/COM interoperation: • Legacy integration • WinForms: • Smart clients, href-exes (executables over HTTP) • Asynchronous execution: • Threads, delegates • Support for event-driven programming in C# • ADO.NET • XML Libraries

More Related