Consuming Web Service from Remote Machine
Consuming simple web service and understanding web service is a little bit difficult at first. It takes some time to understand the theory behind it. In my part, reading will be a good start. Read some articles and basics behind it. But as you move along, consuming will just be a basic part. You need to extend your web service so that it can be used by other application if not from your local, it can be a network, or in the internet.
On this simple article I've created, we will create a simple web service and use it on a local area network. Here are the steps:
1.) Create your web service in your VS 2005 environment, I prefer File - New - Web Site. Then choose ASP.NET Web Service template. Make sure you choose HTTP as your location.
2.) Create your web methods. Sample code below:
[WebMethod]public int Add(int a, int b)
{
return (a + b);
}
[WebMethod]public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
3.) Add a web config file. Add these nodes after system.web so that you can access this web service from a remote machine:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
If you didn't put this, you will encounter this specific error: "The test form is only available for requests from the local machine" if you accessed this web service from a remote machine.
4.) Lastly, because your web service was running on your IIS, you can now accessed it and consumed your web service. For example, I have this remote machine, and my local machine where I published the above web service has a computer named PH-WWDTWDAVID, then I will just add a web reference like this link:
http://ph-wwdtwdavid/WebService/Service.asmx
5.) To use the code:
int xx;
localhost.Service myService = new localhost.Service();
xx=myService.Add(3, 3);
Response.Write(xx.ToString());
Regards,
Willy David Jr