Anatomy of a .Net Web Service
Folks, lets examine how a request for a web service is handled by .Net when it comes in from any client:
------------------------------------------
When a request comes into IIS for a .Net web service, IIS examines the request and determines that it is being sent a file that ends with the extn. .asmx. The ASP.Net handler is registered with IIS as handling this extn.; therefore, this request is handed over to the ASP.Net process.
At this point, the ASP.Net worker process examines the request and discovers that it has a handler registered in machine.config file, for a request for resources with the extn. .asmx. It therefore invokes this handler and passes the request onto it.
Next, the handler creates an instance of the class defined in the handler, and uses reflection to examine which operations the class supports and how those operations should be routed. By default, operations are mapped to methods using the SOAPAction HTTP header, but this can be changed to map to the first child element of the SOAP body.
Once the message is routed, the handler uses the XML Serializer to deserialize the request XML into the parameters the method is expecting. Once the method returns, the return value and any out parameters are mapped back into XML using XML Serializer. Then, a response SOAP message is created that wraps this XML , and the response is sent back via ASP.Net's HTTPResponse context.
If an exception is thrown, then it is wrapped into a SOAPException and a SOAP fault is returned instead, with the HTTP status code set to 500. (For non-error responses, the status code is 200 or OK).
------------------------------------------
When a request comes into IIS for a .Net web service, IIS examines the request and determines that it is being sent a file that ends with the extn. .asmx. The ASP.Net handler is registered with IIS as handling this extn.; therefore, this request is handed over to the ASP.Net process.
At this point, the ASP.Net worker process examines the request and discovers that it has a handler registered in machine.config file, for a request for resources with the extn. .asmx. It therefore invokes this handler and passes the request onto it.
Next, the handler creates an instance of the class defined in the handler, and uses reflection to examine which operations the class supports and how those operations should be routed. By default, operations are mapped to methods using the SOAPAction HTTP header, but this can be changed to map to the first child element of the SOAP body.
Once the message is routed, the handler uses the XML Serializer to deserialize the request XML into the parameters the method is expecting. Once the method returns, the return value and any out parameters are mapped back into XML using XML Serializer. Then, a response SOAP message is created that wraps this XML , and the response is sent back via ASP.Net's HTTPResponse context.
If an exception is thrown, then it is wrapped into a SOAPException and a SOAP fault is returned instead, with the HTTP status code set to 500. (For non-error responses, the status code is 200 or OK).
Comments