Javascript Error: Webservice is undefined,though i have added the webreference

Last post 07-02-2007 5:27 AM by Raymond Wen - MSFT. 8 replies.

Sort Posts:

  • Javascript Error: Webservice is undefined,though i have added the webreference

    06-25-2007, 5:27 AM
    • Participant
      1,353 point Participant
    • Swati Jain
    • Member since 05-24-2006, 12:29 PM
    • Pune
    • Posts 731

    Hello All,

     I have tried the  http://weblogs.asp.net/scottgu/archive/2006/10/22/Tip_2F00_Trick_3A00_-Cool-UI-Templating-Technique-to-use-with-ASP.NET-AJAX-for-non_2D00_UpdatePanel-scenarios.aspx

    I made the change to avoid errors as follows

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="DisplayTime.aspx.cs" Inherits="DisplayTime" %>

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head id="Head1" runat="server">

    <title>Hello World Service</title>

    <%-- <link href="StyleSheet.css" rel="stylesheet" type="text/css" />

    --%>

    <script type="text/javascript" language="javascript" >

     

    function callServer() {SimpleService.GetMessage( $get("Name").value,displayMessageCallback);

    }

     

    function displayMessageCallback(result) {$get("message").innerHTML = result;

    }

     

    </script>

     

    </head>

    <body>

    <form id="form1" runat="server">

     

    <asp:ScriptManager ID="ScriptManager1" runat="server" >

    <Services>

    <%-- <asp:ServiceReference Path="~/SimpleService.asmx" />--%>

    <asp:ServiceReference Path="~/App_Code/SimpleService.asmx"/>

     

    </Services>

    </asp:ScriptManager>

     

    <h1>Hello World Example</h1>

     

    <div>

    Enter Name: <input id="Name" type="text" />

     

    <a href="javascript:callServer();">Call Server</a>-----------Change

    <div id="message"></div>

    </div>

     

    </form>

    </body>

    </html>

     

    Webservice

    /// <summary>

    /// Summary description for SimpleService

    /// </summary>

    [WebService(Namespace = "http://tempuri.org/")]

    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    //[Microsoft.Web.Script.Services.ScriptService]--------->original

    [System.Web.Script.Services.ScriptService]---------->I change it to following as above assembly was throwing the assembly reference error

    public class SimpleService : System.Web.Services.WebService

    {

    public SimpleService()

    {

    //Uncomment the following line if using designed components

    //InitializeComponent();

    }

    [
    WebMethod]public string HelloWorld()

    {

    return "Hello World";

    }

     

     

     

    [
    WebMethod]public string GetMessage(string name)

    {

    return "Hello <strong>" + name + "</strong>, the time here is: " + DateTime.Now.ToShortTimeString();

    }

     

     

    }

     

    What is going wrong with this ?

     

    Swati

    create template

    create site column

    create content type

    Add template and site columns to content type

    Add content type to document library



    ---------------------------------------
    public class Block : System.Web.UI.WebControls.WebParts.WebPart
    {
    string m_scriptBlock = "";
    string m_scriptKey = "scriptKey";

    //Key Property
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true),
    WebDisplayName("Script Key"),
    WebDescription("A unique key for the script.")]
    public string ScriptKey
    {
    get { return m_scriptKey; }
    set { m_scriptKey = value; }
    }

    //Script Property
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true),
    WebDisplayName("Script"),
    WebDescription("The JavaScript to insert in the page.")]
    public string Script
    {
    get { return m_scriptBlock; }
    set { m_scriptBlock = value; }
    }

    protected override void OnPreRender(EventArgs e)
    {
    base.OnPreRender(e);

    if (m_scriptBlock != "" &&
    !Page.ClientScript.IsClientScriptBlockRegistered(m_scriptKey))
    Page.ClientScript.RegisterClientScriptBlock(
    typeof(string), m_scriptKey, m_scriptBlock, true);

    }
    }

    -----------------------------------------






    protected override void CreateChildControls()
    {
    base.CreateChildControls();

    try
    {
    if (_userControl != defaultText)
    {
    _control = this.Page.LoadControl(_userControl);
    }
    else
    {
    _control = new LiteralControl(string.Format("To link to content, open the tool pane and then type a URL in the Link text box.", 1, 129, this.ID));
    }
    }
    catch (System.Exception ex)
    {
    _control = new LiteralControl(string.Format("Error: unable to load {0}
    Details: {1}", _userControl, ex.Message));
    }

    if (_control != null)
    {
    // Add to the Controls collection to support postback
    this.Controls.Add(_control);
    }
    }









    -------------------------------------------------------------------------
    opening the template inline in list view?

    Redirecting different content type to different folder



    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES --for multiple sharepont apps


    ------------------------------------------------------
    For creating webPart automatic

    create blank project --> add new component --> webpart
    --------------------------------------------------------


    custom event Handler
    In class library

    orders.EventReceivers.Add
  • Re: Javascript Error: Webservice is undefined,though i have added the webreference

    06-25-2007, 7:27 AM
    • Member
      18 point Member
    • evilweeble
    • Member since 05-11-2007, 3:18 PM
    • Posts 18

    Try adding the webservice locally to your webapp.  Failing that make a wrapper class that you call from your code behind.  I didn't think AJAX could make calls to webservices that aren't running in the same process.

     

     

  • Re: Javascript Error: Webservice is undefined,though i have added the webreference

    06-25-2007, 8:34 AM
    • Participant
      1,353 point Participant
    • Swati Jain
    • Member since 05-24-2006, 12:29 PM
    • Pune
    • Posts 731

    Will u clarify your solution , what exactly I have to do to solve the situation?

    Swati

    create template

    create site column

    create content type

    Add template and site columns to content type

    Add content type to document library



    ---------------------------------------
    public class Block : System.Web.UI.WebControls.WebParts.WebPart
    {
    string m_scriptBlock = "";
    string m_scriptKey = "scriptKey";

    //Key Property
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true),
    WebDisplayName("Script Key"),
    WebDescription("A unique key for the script.")]
    public string ScriptKey
    {
    get { return m_scriptKey; }
    set { m_scriptKey = value; }
    }

    //Script Property
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true),
    WebDisplayName("Script"),
    WebDescription("The JavaScript to insert in the page.")]
    public string Script
    {
    get { return m_scriptBlock; }
    set { m_scriptBlock = value; }
    }

    protected override void OnPreRender(EventArgs e)
    {
    base.OnPreRender(e);

    if (m_scriptBlock != "" &&
    !Page.ClientScript.IsClientScriptBlockRegistered(m_scriptKey))
    Page.ClientScript.RegisterClientScriptBlock(
    typeof(string), m_scriptKey, m_scriptBlock, true);

    }
    }

    -----------------------------------------






    protected override void CreateChildControls()
    {
    base.CreateChildControls();

    try
    {
    if (_userControl != defaultText)
    {
    _control = this.Page.LoadControl(_userControl);
    }
    else
    {
    _control = new LiteralControl(string.Format("To link to content, open the tool pane and then type a URL in the Link text box.", 1, 129, this.ID));
    }
    }
    catch (System.Exception ex)
    {
    _control = new LiteralControl(string.Format("Error: unable to load {0}
    Details: {1}", _userControl, ex.Message));
    }

    if (_control != null)
    {
    // Add to the Controls collection to support postback
    this.Controls.Add(_control);
    }
    }









    -------------------------------------------------------------------------
    opening the template inline in list view?

    Redirecting different content type to different folder



    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES --for multiple sharepont apps


    ------------------------------------------------------
    For creating webPart automatic

    create blank project --> add new component --> webpart
    --------------------------------------------------------


    custom event Handler
    In class library

    orders.EventReceivers.Add
  • Re: Javascript Error: Webservice is undefined,though i have added the webreference

    06-29-2007, 6:04 AM

    Swati Jain:

    <asp:ServiceReference Path="~/App_Code/SimpleService.asmx"/>

     

    Hi,

    The most significant reason I can think of is that the web service is in the ASP.NET special folder App_Code. Please place it in a different location.

     

  • Re: Javascript Error: Webservice is undefined,though i have added the webreference

    06-29-2007, 8:10 AM
    • Participant
      1,353 point Participant
    • Swati Jain
    • Member since 05-24-2006, 12:29 PM
    • Pune
    • Posts 731

    Hi Raymond ,

     I have changed the path earlier still I got the same error

     //[Microsoft.Web.Script.Services.ScriptService]--------->original

    [System.Web.Script.Services.ScriptService]---------->I change it to following as above assembly was throwing the assembly reference error

    I think its bcoz Microsoft.script.web  attribute is not accepted by  the editor

    create template

    create site column

    create content type

    Add template and site columns to content type

    Add content type to document library



    ---------------------------------------
    public class Block : System.Web.UI.WebControls.WebParts.WebPart
    {
    string m_scriptBlock = "";
    string m_scriptKey = "scriptKey";

    //Key Property
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true),
    WebDisplayName("Script Key"),
    WebDescription("A unique key for the script.")]
    public string ScriptKey
    {
    get { return m_scriptKey; }
    set { m_scriptKey = value; }
    }

    //Script Property
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true),
    WebDisplayName("Script"),
    WebDescription("The JavaScript to insert in the page.")]
    public string Script
    {
    get { return m_scriptBlock; }
    set { m_scriptBlock = value; }
    }

    protected override void OnPreRender(EventArgs e)
    {
    base.OnPreRender(e);

    if (m_scriptBlock != "" &&
    !Page.ClientScript.IsClientScriptBlockRegistered(m_scriptKey))
    Page.ClientScript.RegisterClientScriptBlock(
    typeof(string), m_scriptKey, m_scriptBlock, true);

    }
    }

    -----------------------------------------






    protected override void CreateChildControls()
    {
    base.CreateChildControls();

    try
    {
    if (_userControl != defaultText)
    {
    _control = this.Page.LoadControl(_userControl);
    }
    else
    {
    _control = new LiteralControl(string.Format("To link to content, open the tool pane and then type a URL in the Link text box.", 1, 129, this.ID));
    }
    }
    catch (System.Exception ex)
    {
    _control = new LiteralControl(string.Format("Error: unable to load {0}
    Details: {1}", _userControl, ex.Message));
    }

    if (_control != null)
    {
    // Add to the Controls collection to support postback
    this.Controls.Add(_control);
    }
    }









    -------------------------------------------------------------------------
    opening the template inline in list view?

    Redirecting different content type to different folder



    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES --for multiple sharepont apps


    ------------------------------------------------------
    For creating webPart automatic

    create blank project --> add new component --> webpart
    --------------------------------------------------------


    custom event Handler
    In class library

    orders.EventReceivers.Add
  • Re: Javascript Error: Webservice is undefined,though i have added the webreference

    07-01-2007, 9:42 PM

     It seems that the AJAX extension isn't properly installed on your machine, or you don't have the RTM release installed.

    Please download it here and reinstall it, then try again. 

  • Re: Javascript Error: Webservice is undefined,though i have added the webreference

    07-01-2007, 11:40 PM

    Has your problem resolved yet? Would you share your solution?Thanks

    Jonathan Shen
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Javascript Error: Webservice is undefined,though i have added the webreference

    07-02-2007, 3:37 AM
    • Participant
      1,353 point Participant
    • Swati Jain
    • Member since 05-24-2006, 12:29 PM
    • Pune
    • Posts 731

    I have installed the Ajax extension 1.0 again and I searched for  the Microsoft.Web.Extensions.dll but i didnt get it.

    Can you post the structure of the web.config file .?

     

    create template

    create site column

    create content type

    Add template and site columns to content type

    Add content type to document library



    ---------------------------------------
    public class Block : System.Web.UI.WebControls.WebParts.WebPart
    {
    string m_scriptBlock = "";
    string m_scriptKey = "scriptKey";

    //Key Property
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true),
    WebDisplayName("Script Key"),
    WebDescription("A unique key for the script.")]
    public string ScriptKey
    {
    get { return m_scriptKey; }
    set { m_scriptKey = value; }
    }

    //Script Property
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true),
    WebDisplayName("Script"),
    WebDescription("The JavaScript to insert in the page.")]
    public string Script
    {
    get { return m_scriptBlock; }
    set { m_scriptBlock = value; }
    }

    protected override void OnPreRender(EventArgs e)
    {
    base.OnPreRender(e);

    if (m_scriptBlock != "" &&
    !Page.ClientScript.IsClientScriptBlockRegistered(m_scriptKey))
    Page.ClientScript.RegisterClientScriptBlock(
    typeof(string), m_scriptKey, m_scriptBlock, true);

    }
    }

    -----------------------------------------






    protected override void CreateChildControls()
    {
    base.CreateChildControls();

    try
    {
    if (_userControl != defaultText)
    {
    _control = this.Page.LoadControl(_userControl);
    }
    else
    {
    _control = new LiteralControl(string.Format("To link to content, open the tool pane and then type a URL in the Link text box.", 1, 129, this.ID));
    }
    }
    catch (System.Exception ex)
    {
    _control = new LiteralControl(string.Format("Error: unable to load {0}
    Details: {1}", _userControl, ex.Message));
    }

    if (_control != null)
    {
    // Add to the Controls collection to support postback
    this.Controls.Add(_control);
    }
    }









    -------------------------------------------------------------------------
    opening the template inline in list view?

    Redirecting different content type to different folder



    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES --for multiple sharepont apps


    ------------------------------------------------------
    For creating webPart automatic

    create blank project --> add new component --> webpart
    --------------------------------------------------------


    custom event Handler
    In class library

    orders.EventReceivers.Add
  • Re: Javascript Error: Webservice is undefined,though i have added the webreference

    07-02-2007, 5:27 AM
    Answer

    Its name is changed to System.Web.Extensions. 

Page 1 of 1 (9 items)