So, until not too long ago, to create a .NET Web Service I always did the “normal” thing. I would open up visual studio, pull up my existing solution or create a new one and within it I would create a Web Service Application. However, Chad a fellow developer (a “Junior”), recently informed me of a much easier way to do this.
Say you have a class library application or any regular class with methods. Within the class file itself, only one simple change is made. The class must inherit from MarshalByRefObject. Look at the image below to see this applied to a simple calculator class.
Now, to get this to work… In IIS or wherever this is being hosted, there must be a bin directory. So, place the .dll for this file in this bin directory. Next, in the parent folder of the bin directory, there must be a web.config file. In this web config, one must have the following xml:
Here is a snapshot of the folder structure in regards to the SimpleCalc webservice:
The WebService WSDL URL is now “servername/IISdirectoryname/objecturi?wsdl,” where objecturi is specified in the web.config as shown below for this case.
You can call this web service just like any other. However, the structure of the class seems sort of like a Remoting object, so I might get someone to confirm. But even though this might be the case, it is exposing the class as a web service. I believe to make the methods accessible, they only have to be marked with the “public” access modifier.
Thanks again, Chad!