Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 16th, 2010, 07:16 PM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
Default 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!
Reply With Quote
  #2 (permalink)  
Old January 21st, 2010, 01:09 PM
Registered User
 
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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. :)
Reply With Quote
  #3 (permalink)  
Old January 21st, 2010, 01:38 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Ken,

Your post has reappeared! And ues, can you post the code behind of the page as well?

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!
Reply With Quote
  #4 (permalink)  
Old January 21st, 2010, 01:48 PM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
Default

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
Reply With Quote
  #5 (permalink)  
Old January 21st, 2010, 02:01 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
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!
Reply With Quote
  #6 (permalink)  
Old January 21st, 2010, 03:29 PM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
Default

yes - I edited my post to include the file
Ken
Reply With Quote
  #7 (permalink)  
Old January 21st, 2010, 06:56 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
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!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
ken evans (January 22nd, 2010)
  #8 (permalink)  
Old January 22nd, 2010, 07:28 AM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
Default

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
Reply With Quote
  #9 (permalink)  
Old January 22nd, 2010, 10:15 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Great; glad it's working and thanks for the follow up....

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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Used-to-work aspx page now not working tanakrita ASP.NET 1.0 and 1.1 Basics 1 October 22nd, 2009 01:28 PM
On page 799 the code doesn't seem to work? RPA Solutions BOOK: Professional ASP.NET 3.5 SP1 Edition: In C# and VB 4 July 9th, 2009 06:11 AM
Chapter 6, page 201,Try it out does not work. VictorVictor BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 2 January 30th, 2006 02:20 PM



All times are GMT -4. The time now is 06:38 PM.


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