January 11, 2008


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

No comments: