 |
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
|
|
|
|

January 16th, 2010, 07:16 PM
|
Authorized User
|
|
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
|
|
Page 344 Try-It-Out does not work
After lots of tests, I can't get the try-it-out code for "Calling Web Services from Client Code" to work. (Described on pages 344-345)
The page displays OK in the browser.
But, when I enter my name and press the âSay Helloâ button, nothing happens.
When I used the ErrorCallback(error) described on page 347,
I saw an error message that said that "yourName" is not declared.(or similar). The error referenced the client line of code that says:
NameService.HelloWorld(yourName, HelloWorldCallback);
Anyone got any clues on the cause of this problem?
I checked the code several times but I can't see any errors.
Anyway here is the code for the WebServices.aspx :
Code:
<%@ Page Title="Web Services Demo" Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true" CodeFile="WebServices.aspx.cs" Inherits="Demos_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" name="txtYourName" />
<input id="btnSayHello" type="button" value="Say Hello" />
<script type="text/javascript">
function HelloWorld()
{
var yourName = $get('txtYourName').value;
NameService.HelloWorld(yourName, HelloWorldCallback);
}
function HelloWorldCallback(result)
{
alert(result);
}
$addHandler($get('btnSayHello'), 'click', HelloWorld);
</script>
</asp:Content>
Note: I posted this yesterday but somehow it disappeared so here it is again!
|

January 21st, 2010, 01:09 PM
|
Registered User
|
|
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
yo friend,
can i see your .cs? i realized it's a good thing to help others once i got that part working on my end. helps me learn to debug as well. :)
|

January 21st, 2010, 01:38 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Ken,
Your post has reappeared! And ues, can you post the code behind of the page as well?
Imar
|

January 21st, 2010, 01:48 PM
|
Authorized User
|
|
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
|
|
Here is the code behind.
Thanks for your help.
Ken
WebServices.aspx.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Demos_WebServices : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
NameService.asmx
Code:
<%@ WebService Language="C#" CodeBehind="~/App_Code/NameService.cs" Class="NameService" %>
NameService.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
/// <summary>
/// Summary description for NameService
/// This is the code-behind for the Web Service NameService.asmx.
/// Visual Studio automatically puts the code-behind for a web service into the App_Code folder.
/// </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
{
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);
}
}
Last edited by ken evans; January 21st, 2010 at 02:06 PM..
Reason: add code
|

January 21st, 2010, 02:01 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Ken,
Quote:
I now see that, whilst it is referenced, I don't have a file called NameService.cs
It's been a while so I'm not sure if I should have one or not.
|
Yes, you should have one, and it's located in the App_Code folder....
Can you post the full code from the ASMX file and its Code Behind .cs file?
Cheers,
Imar
|

January 21st, 2010, 03:29 PM
|
Authorized User
|
|
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
|
|
yes - I edited my post to include the file
Ken
|

January 21st, 2010, 06:56 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Your HelloWorld service method has two parameters while your JavaScript only passes one. Update HelloWorld as shown in the book and it should work.
Cheers,
Imar
|
The Following User Says Thank You to Imar For This Useful Post:
|
|

January 22nd, 2010, 07:28 AM
|
Authorized User
|
|
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
|
|
Thanks Imar.
Problem solved!
I caused this problem myself by experimenting with multiple parameters at the name service level described in the try-it-out on page 338. But then I forgot to remove the second parameter when I moved on to the try-it-out on page 344.
Ken
|

January 22nd, 2010, 10:15 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Great; glad it's working and thanks for the follow up....
Imar
|
|
 |