Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 28th, 2011, 11:46 AM
Registered User
 
Join Date: Sep 2011
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Default Chp 10 Try it Out (calling WS from Client code) not working

Hello:

When i open in browse, after entering name, press Say Hello Button, Alert Window is not appearing.

Thanks in Advance


Please in the code :

Webservices.aspx
------------------
<%@ Page Title="Web Services Demo" Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true" CodeFile="WebServices.aspx.cs" Inherits="Demo_WebServices" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
<Services>
<asp:ServiceReference Path="~/WebServices/NameService.asmx" />
</Services>
</asp:ScriptManagerProxy>


<input id="txtYourName" type="text" />
<input id="btnSayHello" type="button" value="Say Hello" />

<script type="text/javascript" >

function HelloWorld() {

var youName = $get('txtYourName').value;
NameService.HelloWorld(yourName, HelloWorldCallback);

}

function HelloWorldCallback(result) {

alert(result);
}

$addHandler($get('btnSayHello'), 'click', Helloword);

</script>


</asp:Content>

Code file is not touch in this example.


Masterpage.aspx
------------------
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/WebServices/NameService.asmx" />
</Services>

</asp:ScriptManager>


NameService.asmx in Webservice folder
-----------------
<%@ WebService Language="C#" CodeBehind="~/App_Code/NameService.cs" Class="NameService" %>


NameService.cs in App_code
--------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

/// <summary>
/// Summary description for NameService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class NameService : System.Web.Services.WebService {
string yourname;
public NameService () {

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public string HelloWorld(string firstname, string lastname) {
return string.Format("Hello {0} {1}", firstname, lastname);
}

}
 
Old October 7th, 2011, 03:18 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Check your code / spelling. You're mixing stuff like youName / yourName and HelloWorld / Helloword etc.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Client code for Chp 7 UoW mwiza BOOK: Professional ASP.NET Design Patterns 1 September 20th, 2011 09:00 AM
How to INVOKE any WS on server by WS on client ? Abhinavnaresh ASP.NET 2.0 Professional 1 April 4th, 2008 01:09 PM
WS client sending compressed request? wakeup .NET Web Services 0 October 25th, 2007 04:37 AM
Calling WS from javascript r_ganesh76 Javascript 5 December 8th, 2004 05:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.