Sunday, March 11, 2012

Problem Webservice

Hi Tanielian,

I hope you are using MS Ajax 1.0. Below is an example which should work:

You have to add a Scriptmanager to your webpage. This control will create a proxy for you, so You can make requests to the webservice.

<body>
<formid="form1"runat="server">
<asp:ScriptManagerID="ScriptManager1"runat="server">
<Services>
<asp:ServiceReferencePath="WebService.asmx"/>
</Services>
</asp:ScriptManager>
<div>
<inputid="btnClick"type="button"value="button"onclick="return btnClick_onclick()"/> </div>
</form>
</body>

You have to add a javascript function which will invoke the webservice. See below:

<scriptlanguage="javascript"type="text/javascript">
// <!CDATA[
functionbtnClick_onclick() {
WebService.HelloWorld(onSuccess);
}
function onSuccess(response) {
alert(response);
}
// ]]>
</script>

The last thing you need to do is create a new webservice. When you do this there will be standard a method "Helloworld". Add the following namespace to you asmx.cs: "System.Web.Script.Services". The last thing that you have to do is add a attribute to above webservice class --> [Scriptservice]. So your webservice is now able to process call from Javascript. When you copy this code make sure that the name of your webservice is WebService and that it is in the same folder as your webpage because the reference i give you will look for the webservice in the same folder as your webpage: "<asp:ServiceReferencePath="WebService.asmx"/>"

Hope this Helps,


I'm sorry for taking so long to reply your post..

I was in a travel...

Thanks a lot... it realy works...

you saved my skin... thanks a lot...

No comments:

Post a Comment