How do i Consume web Service in my app [Resolved]

Posted by Self-Innovator under ASP.NET AJAX on 4/11/2012 | Points: 10 | Views : 2068 | Status : [Member] | Replies : 9
hi frnds....
I am new to web service how to Consume the below created web service but i didn't get the o/p...
(WebService.asmx)
[WebMethod]
public string OurServerOutput()
{
return "The Server Date and Time is:" + DateTime.Now.ToString();
}

FirstWebService.aspx This is Ajax Enabled Site
<script type="text/javascript" language="javascript">
function CallDateTime()
{
WebService.OurServerOutput(OnSucceeded);
}
function OnSucceeded(result)
{
var lblOutput=document.getElementById("Label1");
Label1.innerHTML=result;
}
</script>


<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="WebService.asmx" />
</Services>
</asp:ScriptManager>
&nbsp;<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" OnClientClick="CallDateTime()" Text="Call Web Service" />


Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Rajni.Shekhar on: 4/11/2012 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Add your service reference by right click on your application, there would be an option to add service reference, give URL of your service there, it will be added to your application.
Now add name space of your web service to your page.

using ServiceReference1;


Create object of service class

ServiceReference1.ServiceSoapClient obj = new ServiceSoapClient();


Access your method.

Response.Write(obj.OurServerOutput());


Thanks,
Rajni Shekhar

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 4/11/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
where u got error dude...

Thanks & Regards
Hari

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-Innovator on: 4/11/2012 [Member] Bronze | Points: 25

Up
0
Down
No errors i didnt got an O/p

Join Hands Change lives
Thanks & Regards
Straight Edge Society

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 4/11/2012 [Member] Bronze | Points: 25

Up
0
Down
do you want to consume web service by javascript only?

Thanks,
Rajni Shekhar

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-Innovator on: 4/11/2012 [Member] Bronze | Points: 25

Up
0
Down
hi rajini....Shekar
Not only in javascript Even im Normal way I wanted to consume the Service...In above example i've used javascript...According to my above program result shud be an Server Time On clienclik Event of button...hope u find better soln

Join Hands Change lives
Thanks & Regards
Straight Edge Society

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 4/11/2012 [Member] Bronze | Points: 25

Up
0
Down
check below site to use webservice method in javascript

http://forums.asp.net/t/1302025.aspx/1


Thanks,
Rajni Shekhar

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 4/11/2012 [Member] Bronze | Points: 25

Up
0
Down
You can also consume webservice in you application by adding service reference to your application and add name space of service in your page.
Create a object of web service client, access your method to get the out put.

Thanks,
Rajni Shekhar

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-Innovator on: 4/11/2012 [Member] Bronze | Points: 25

Up
0
Down
S rajini..
Nice Links and i wanted to achieve or consume the web service from the last method which u mentioned by adding the namespace....In a page.Will u pls get me some small example of this type and provide me as an attach file bcoz i'm new to web service....I've tried by typing the name of service the intellisense is not getting reflectd...

Join Hands Change lives
Thanks & Regards
Straight Edge Society

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-Innovator on: 4/11/2012 [Member] Bronze | Points: 25

Up
0
Down
Yes thanks Rajini....to spend your time nw it wrks....

Join Hands Change lives
Thanks & Regards
Straight Edge Society

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response