January 22, 2008

MVC in ASP.NET

MVC - Model-View-Controller is a sort of design pattern used to develop applications in an uncoupled manner i.e. seperate the data (Model) from the User interface (View) and the business logic (Controller).

I first came across this with MFC applications, it was well known design pattern when developing standalone applications now it appears to be the latest craze in ASP.NET 3.5 applications! In this post I'll try and find out why and what is the significance and benefits to us, developers.

MVC (scott gu)
Example Building a Simple Blog engine using MVC in ASP.NET (aspalliance.com)

January 11, 2008

WebServices

Webservices are exposed methods which can be accessed through a uri e.g.your code is contained in a .asmx file.
The .asmx file contains webmethods (ordinary methods with the [WebMethod] attribute). You place your .asmx file inside your webserver somewhere and these can be consumed directly by browsing to the uri or by consuming the webservice by adding it as a reference to your application and then accessing that reference. Webservices can also be created with Codebehind meaning the code itself is in another file, this results in the .asmx file just containing a Directive to the class name containing the webmethod, to use this webservice the codebehind dll must be placed within the websites bin directory.

The WebService works by the Client and Server sending SOAP XML (SOAP is just the root element, it's something that Internet Explorer knows how to parse) up and down over HTTP. Both sides need to know how to create this SOAP XML, on the Client side this is done by a Proxy class which Serializes/De-Serializes the SOAP XML into objects.

Proxy Class

Client side class, usually called Reference.cs, which Serializes/De-Serializes the SOAP XML into objects. This lives on the Client side (in .NET) e.g. if the client is an .NET Console application then in order to gain access to the methods available on a website the application will need a Proxy class (this is created for you by VS.NET when you add a Web Reference which points to the Webservice on the website i.e. http:..........).
If you want to use Webservices from a Client such as an ASPX form then you again need to add the Web Reference but a Proxy class is not generated, instead because your making calls on the same web application you can call into the WebService class directly like a normal class.
If your calling a WebService from on Web app to another then it's the same as a Console app, you'' have to use a Proxy class, again this is generated for you in the calling website by VS.NET when you add the Web Reference.

Hiding the asmx

I have not actually found a way to get rid of the .asmx file completely. You can hide the webservice endpoints functionality in an assembly and create a handler for it as described below but to implement the webservice you will always need a .asmx file somewhere. Even the Proxy Class uses the .asmx file. In order to implement a remote call to a method inside your own code I think the only solution is .NET Remoting.


An Extensive Examination of WebServices (4guysfromrolla thorough).
Creating a .NET Web Service (15seconds goood)
ASP.NET Web Services Techniques (Very thorough explanation of how WebServices work)
Writing a raw Web Service using HttpHandler

January 07, 2008

Active Directory

Active Directory is the windows method to access all distributed devices such as files, printers.

In .NET the Active Directory is accessed from System.DirectoryServices namespace.

.NET uses Windows Active Directory Service Interfaces (ADSI) to interact with the distributed devices, there are 5 of these ADSIs;
Path Windows NT version 5.0, Windows 2000, or Windows XP WinNT://path, Lightweight Directory Access Protocol (LDAP) ldap://path/, Novell NetWare Directory Service NDS://path, Novell Netware 3.x NWCOMPAT://path, Internet Information Services (IIS) IIS://.

e.g.

DirectoryEntry webentry = new DirectoryEntry();
String path = "IIS://localhost/W3SVC/1/ROOT";


DirectoryEntries webSiteChildren = webentry.Children;
foreach (DirectoryEntry website in webSiteChildren)
{

//can access metadata of each website on iis here
}