 |
BOOK: Beginning ASP.NET 4 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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
|
|
|
|
|

October 18th, 2010, 07:36 AM
|
|
Authorized User
|
|
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
|
|
Ch10 - page 354 step 7 - No Function
Hello again!
Step 7 does not work for me.
The page "WebServices.aspx" displays without error.
But when I type my name and press the "SayHello" button, nothing happens.
The code is below.
Any clues?
Thanks
Ken
WebServices.aspx
Code:
<%@ Page Title="Web Services Demo" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="WewbServices.aspx.cs" Inherits="Demos_WewbServices" %>
<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="YourName" type="text" />
<input id="SayHello" type="button" value="SayHello" />
<script type="text/javascript">
function HelloWorld()
{
var yourName = $get('YourName').value;
NameService.HelloWorld(yourName, HelloWorldCallback);
}
function HelloWorldCallback(result)
{
alert(result);
}
$addHandler($get('SayHello'), 'click', HelloWorld);
</script>
</asp:Content>
NameServices.cs
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. Ref: page 351 & 353.
[System.Web.Script.Services.ScriptService]
public class NameService : System.Web.Services.WebService {
public NameService ()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
// this code is updated from page 351 in the book to show three parameters with different data types
[WebMethod]
public string HelloWorld(string firstName, string lastName, int age)
{
return string.Format("Hello {0} {1} {2}", firstName, lastName, age);
}
}
NameService.asmx
Code:
<%@ WebService Language="C#" CodeBehind="~/App_Code/NameService.cs" Class="NameService" %>
Last edited by ken evans; October 18th, 2010 at 07:37 AM..
Reason: typo
|
|

October 18th, 2010, 07:49 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Code:
public string HelloWorld(string firstName, string lastName, int age)
You made up parameters in the web service that you're not passing to it from the client side code. This should work:
Code:
public string HelloWorld(string firstName)
or this:
Code:
NameService.HelloWorld(yourName, "LastName", 39, HelloWorldCallback);
Hope this helps,
Imar
---------------------------------------------------------------------------------------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter
Author of Beginning ASP.NET 4 : in C# and VB, Beginning ASP.NET 3.5 : in C# and VB and ASP.NET 2.0 Instant Results.
While typing this post, I was listening to: Station Approach by Elbow (From the album: Leaders of the Free World) What's This?
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

October 18th, 2010, 08:01 AM
|
|
Authorized User
|
|
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
|
|
Thanks Imar,
It's all working now.
I used the " firstName, lastName, age" code to experiment with multiple parameters in the previous exercise. It worked OK there but clearly broke things in this exercise.
Ken
|
|

January 27th, 2012, 08:25 AM
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Problem with Calling Web Services from Client-Side Code
Hello!
I got a problem while writing the code of the try it out on the page 352.
At step 6, when writing
Code:
var yourName=$get('YourName').value
the .value does not highlighted from intellisence.
When I request the page in the browser, will be loaded, but writing in the textbox and pressing the button does not alert the message.
Any Idea?
Thank's in advance
|
|

January 27th, 2012, 10:08 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
the .value does not highlighted from intellisence.
|
This is by design. Visual Studio doesn't know the return value of $get has a value property. This is because of the untyped nature of JavaScript.
Quote:
|
but writing in the textbox and pressing the button does not alert the message.
|
Could be anything. Can you post the code for the page as well as the code for the web service? And have you tried debugging your code?
Imar
|
|

January 27th, 2012, 02:12 PM
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Problem on client side for web servcice
Thanks, Imar for you direct responce.
the code in Web Sevice Demo page is the following
Code:
<%@ Page Title="Web Services Demo" Language="C#" MasterPageFile="~/MasterPages/Frontend.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>
<script type="text/javascript">
function HelloWorld() {
var yourName = $get('YourName').value;
NameService.HelloWorld(yourName, HelloWorldCallback, ErrorCallback);
}
function HelloWorldCallback(result) {
alert(result);
}
function ErrorCallback(error) {
alert(error.get_message);
}
$addHandler($get('sayHello'), 'click', HelloWorld());
</script>
<input id="YourName" type="text" />
<input id="SayHello" type="button" value="Say Hello" />
</asp:Content>
The Web service does work. I have tested many times. So the problem is not surely in the web service. Hence, I don't post the coressponding code.
No, I didn't debug my code.
Thank you in advance for your help.
By the chance, your book is really amazing. I have read it from the cover to the 354 page and I hadn't any problem. Also I have learned many things until know.
Christos
|
|

January 28th, 2012, 03:31 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
So the problem is not surely in the web service. Hence, I don't post the coressponding code.
|
Since it only takes a few seconds, you're probably better off posting the full code if you want people to look at your problem. The service may work by itself, but that doesn't mean it's named correctly, or has script services enabled or has any other problem.
Anyway, that doesn't seem to be the problem here.
Quote:
|
No, I didn't debug my code.
|
Probably a good habbit to get used to. Chapter 18 has the full details in case you want to know more. When you debug, it's easy to see if references are OK (they are not, in this case) and which code gets called.
Take a look at this:
Code:
$addHandler($get('sayHello'), 'click', HelloWorld());
You're using sayHello while the control is called SayHello with an upper case S.
Quote:
|
By the chance, your book is really amazing. I have read it from the cover to the 354 page and I hadn't any problem. Also I have learned many things until know.
|
Really glad to hear that. Thanks!
Imar
|
|

January 30th, 2012, 07:51 PM
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks
Imar thank's a lot for the hints. They really helped !
Thank's again for the direct responce.
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Page 354 Chapter 10 |
tariq |
BOOK: Beginning ASP.NET 4 : in C# and VB |
4 |
August 20th, 2010 10:33 AM |
| Chapter 5 page 156 Example Step 4 |
NoraBelle |
BOOK: Professional Microsoft SQL Server 2008 Integration Services ISBN: 978-0-470-24795-2 |
1 |
August 2nd, 2010 03:29 PM |
| Chapter 11 Page 354 |
skijor |
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 |
6 |
August 9th, 2009 08:02 AM |
| Page 222 Step 5 |
Whitney Schopf |
BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 |
1 |
November 6th, 2006 06:43 AM |
| step of opening a web page |
somnath.kartic |
VS.NET 2002/2003 |
0 |
March 30th, 2006 03:24 AM |
|
 |
|