Thursday 26 September 2013

How to create / use web service

For an overview, we create a webservice project and a website calling that web service.
Web service project looks like below and is under localhost

Web site looks like as below and is under c:\work.



Firstly, I followed the link below showing nicely how to create web service and use it.
http://msdn.microsoft.com/en-us/library/8wbhsy70(v=vs.90).aspx

I started following the link above and created a web service web application. My localhost inetmgr looks like below. I haven't changed any Advanced settings in IIS but just uploaded the capture here for future reference.





The web service is a small program changing F temperature to C.



If you mess up Application Pool you can get this error:

Otherwise, you can see the working page as below:

Then I launched the webservice to live server. This just meant copying whole folder from localhost to the server folder.

Once I change to live server from localhost, I got the below error:
It was because my folder on webserver was not set up as web application.

After changing it to Application, the web service URL starts working.
 But the F to C change function says, it only works in localhost.
 After searching on Google, i found that it's not error, but for security.

Web service is now working. Next step is to use it.
Create another website and call it. I couldn't find web reference, so i clicked 'Add Service Reference'.
 Put the live URL and name web service.
 In Default.aspx, put some controls.
 On source code behind, when you type in 'temp...' it automatically recognzie the webservice name TemperatureConvert. Good!

Note the code part how to use the webservice and its function. It's slightly different from what you can find from Google. I don't know. It worked that way in my case.

The program works fine.
 It looks exactly same as the MSDN website.

That's it for this blog.

Next step will be passing XML through web service:
http://msdn.microsoft.com/en-us/library/58a18dwa.aspx