Static News Archive

   (29-Aug-07 9:52)  Calling Webservices from webpages
There are a multitude of ways to call asp web services from your webpage.

I spent a while trying to figure out how to get anchor tags to call webservices such as:

<a href="MyWebService.asmx/DoStuff?value1=1234&value2=5678" >::Make anchor call to webservice::</a>

To do this, you will need to add some settings to your web.config to allow the strange syntax "mywebpage.asmx/strangeBit" :

<add name="HttpGet"/>
<add name="HttpPost"/>
<add name="AnyHttpSoap"/>

This also allows non-local users to call your web service using a form:

<form action="MyWebService.asmx/DoStuff" method="post" enctype="application/x-www-form-urlencoded">
<input type="text" name="value1"/>
<input type="text" name="value2"/>
<input type="submit" value="Call webservice"/>

You can of course call web services using your server side aspx code:

if (Page.IsPostBack)
MyWebService wmc = new MyWebService();
string response = wmc.DoStuff(Page.Request["value1"],Page.Request["value2"]);
//write the response to the header of the page
StringBuilder builder = new StringBuilder();
ClientScript.RegisterStartupScript(this.GetType(), "response", builder.ToString(), false);

NB - my web services return strings that can be compiled into javascript objects using eval() - this is through the magic of JSON

So there you have it - 3 ways to call a web service in html, and aspx pages.

Post a comment     

<-  (27-Aug-07 9:01)  automation server ca... (25-Sep-07 13:42)  Setting up IIS for d...  ->