Web services are Application Programming Interfaces (API) or web APIs that can be accessed over a network, such as the Internet, and executed on a remote system hosting the requested services. In common usage the term refers to clients and servers that communicate over the Hypertext Transfer Protocol (HTTP) protocol used on the web (wikipedia).
I just created my first own (very simple) web service and tested it with PowerShell 2.0.
I used Microsoft Visual Web Developer 2008 Express Edition, which is a free version of the MS software. I have found a nice tutorial which helped me to build my web service (here).
Start Visual Web Developer 2008;
On the File menu, choose New Web Site;
In the New Web Site dialog box, select the ASP.NET Web Service icon, at the bottom of this screen you can select Visual Basic or C# as the language for your web service. I like to use C#;
In the following text screen, select and delete everything below "using System.Web.Services;"
Now, paste this contents below "using System.Web.Services;":
[System.Web.Services.WebService(
Namespace = "http://Walkthrough/XmlWebServices/",
Description = "A temperature conversion service.")]
public class Service : System.Web.Services.WebService
{
[WebMethod(Description = "This method converts a temperature in " +
"degrees Fahrenheit to a temperature in degrees Celsius.")]
public double ConvertTemperature(double dFahrenheit)
{
return ((dFahrenheit - 32) * 5) / 9;
}
}
See if the code is working by using the Debug function in the menu toolbar;
If everything works fine, click OK to create the project.
Select all the files located in ~\My Documents\Visual Studio 2008\WebSites\WebSite1 and paste it in a new folder located in C:\Inetpub\wwwroot (for example C:\Inetpub\wwwroot\firstwebservice)
Now, open http://localhost/webservice/Service.asmx in your internet browser and see what happens.
If you get an error telling you there's something wrong with:
Line 25: <authentication mode="Windows" />
Go to the control panel, to the IIS panel on the Web Server and open the default Web Site, find the folder for your application, right click it, choose properties and then in the screen that opens up, hit CREATE (a button). OK your changes and try again.
If everything is working, start PowerShell 2.0 and use the following command:
$ws = new-webserviceproxy http://localhost/webservice2/Service.asmx
$ws.ConvertTemperature(100)
If everything has worked as it should, you now see the web service has converted 100 degrees Fahrenheit to 37,7777 degrees celcius. Now, you can decide to copy the files to any other server somewhere in the big wide world, because when it works with localhost, it should also work with any other server.
If you want to know what else your web service can do, use this PowerShell command:
$ws = new-webserviceproxy http://localhost/webservice2/Service.asmx
$ws | get-member
and take a look at the output.
Now, I have to expand the functions of my web service and make it more usefull. But, I'm glad that I have managed it so far...
Recent Comments