View Single Post
  #1 (permalink)  
Old October 18th, 2010, 07:36 AM
ken evans ken evans is offline
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 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
Reply With Quote