For a while I'd heard about webservices and thought that they could be useful, when an idea came up at work to provide remote services to clients i thought I'd better find out how it all worked.
First of all I wrote my own web service; http://beanengineering.co.uk/webservices/webservice.asmx, its very simple and has two functions one returns the words "Hello World"and the other returns 10 * 3. I know that they are of no real use to anyone but I needed a simple starting point, from here I could then get to grips with using the remote functions.
First of all we need to reference the webservice, this is done in the web.config file (you can also use the add web reference wizard of Visual Studio).
web.config
<appSettings>
<add key="beanengineering.webservice" value="http://beanengineering.co.uk/webservices/webservice.asmx"/>
</appSettings>
The we have a couple of labels to display the results.
webservice.aspx
<asp:Label ID="lblHelloWord" runat="server" Text=""></asp:Label>
<asp:Label ID="lblIntTest" runat="server" Text=""></asp:Label>
Finally the code to run the functions.
webservice.aspx.cs
1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Web;
5: using System.Web.UI;
6: using System.Web.UI.WebControls;
7:
8: public partial class webservice : System.Web.UI.Page
9: {
10: protected void Page_Load(object sender, EventArgs e)
11: {
12: uk.co.beanengineering.WebService ws = new uk.co.beanengineering.WebService();
13: lblHelloWord.Text = ws.HelloWorld().ToString();
14: lblIntTest.Text = ws.TestInt().ToString();
15: }
16: }
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5