Ajax enabled WCF Service stops working with Undefined error

Last post 12-17-2009 10:33 AM by LotusShiv. 21 replies.

Sort Posts:

  • Ajax enabled WCF Service stops working with Undefined error

    02-22-2009, 12:56 PM
    • Member
      3 point Member
    • rdagger
    • Member since 03-11-2008, 1:13 AM
    • Posts 16

     I have an Ajax Enabled WCF service that I call from Javascript.  It works fine, but often after I make unrelated changes to the website it will fail and Javascript will report an 'Undefined' error.  I can easily fix it by deleting the service, removing the system.serviceModel section of the Web.config and then recreating the service.  I don't have to change any of the references in the .aspx or .js files.  Also, the replacement service has identical code in the .config, .cs and .svc files (I don't see any differences).  This morning, I only made some cosmetic changes and the service stopped working again. 

    Any insight into what I am doing wrong?

    Filed under:
  • Re: Ajax enabled WCF Service stops working with Undefined error

    02-24-2009, 1:34 PM
    • Member
      3 point Member
    • rdagger
    • Member since 03-11-2008, 1:13 AM
    • Posts 16
    In the past 2 weeks, I've had to recreate this WCF service a dozen times and I can't see any pattern.  It occurs intermittently when I make edits to the site.
  • Re: Ajax enabled WCF Service stops working with Undefined error

    02-24-2009, 9:56 PM

    Hi, 

    Please check this link http://msdn.microsoft.com/en-us/library/bb924552.aspx

    Did you follow this way to build WCF? Please pay attention that if you used the namespace on WCF, you need use namespace.classname to call the web method.


    Vince Xu
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Ajax enabled WCF Service stops working with Undefined error

    02-25-2009, 7:29 PM
    • Member
      3 point Member
    • rdagger
    • Member since 03-11-2008, 1:13 AM
    • Posts 16

    Vince Xu - MSFT:

    Hi, 

    Please check this link http://msdn.microsoft.com/en-us/library/bb924552.aspx

    Did you follow this way to build WCF? Please pay attention that if you used the namespace on WCF, you need use namespace.classname to call the web method.

    I'm not using a namespace.  The service works.  I just want to know why I keep having to recreate it after making edits to the project.
  • Re: Ajax enabled WCF Service stops working with Undefined error

    02-25-2009, 10:13 PM

    Hi,

    Ajax JavaScript will generate the client agent class for the current web service. After you edit the WCF reference, you need to regenerate these javacript client agent class. Otherwise, the client class will not be updated.

     


    Vince Xu
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Ajax enabled WCF Service stops working with Undefined error

    02-26-2009, 2:22 PM
    • Member
      3 point Member
    • rdagger
    • Member since 03-11-2008, 1:13 AM
    • Posts 16

    Vince Xu - MSFT:

    Hi,

    Ajax JavaScript will generate the client agent class for the current web service. After you edit the WCF reference, you need to regenerate these javacript client agent class. Otherwise, the client class will not be updated.

    I'm not sure I understand.  I haven't been editing the WCF reference or the WCF service.  This morning I made a change to an unrelated page that has no Ajax.  Nonetheless, I checked the WCF service  and it had stopped working and I had to recreate it.

  • Re: Ajax enabled WCF Service stops working with Undefined error

    03-13-2009, 11:27 AM
    • Member
      44 point Member
    • trans642
    • Member since 05-01-2006, 8:18 PM
    • Posts 26

    How ?

     

    I am having similar issues the namespace defined in the service is not recognizable in clientside :

    it keeps on giving me "MySerivce" is undefined

    where MyService is  [ServiceContract(Namespace = "MyService")]

    I have never able to make this ting work in real developement environment; any dummy project is working fine

  • Re: Ajax enabled WCF Service stops working with Undefined error

    03-13-2009, 12:00 PM
    • Member
      44 point Member
    • trans642
    • Member since 05-01-2006, 8:18 PM
    • Posts 26

    this is the solution


    1) Make sure you install .NET 2.0 and 3.0  and 3.5 properly.

    2) Open IIS manager

    3) Open your web directory properties windows.

    4) Make sure ASP.NET version 2 is chosen in ASP.NET tab.

    5) Make sure your script mapping for .svc is using aspnet_isapi.dll from .net 2.0 folder (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll), you could even remove and add again for .svc extension, for all verbs.

     

  • Re: Ajax enabled WCF Service stops working with Undefined error

    03-13-2009, 3:24 PM
    • Member
      3 point Member
    • rdagger
    • Member since 03-11-2008, 1:13 AM
    • Posts 16

    trans642:

    this is the solution

    1) Make sure you install .NET 2.0 and 3.0  and 3.5 properly.

    2) Open IIS manager

    3) Open your web directory properties windows.

    4) Make sure ASP.NET version 2 is chosen in ASP.NET tab.

    5) Make sure your script mapping for .svc is using aspnet_isapi.dll from .net 2.0 folder (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll), you could even remove and add again for .svc extension, for all verbs.

    It may be the solution to your problem, but it doesn't address my issue.  My code works fine in development and production.  Occasionally it will stop working after I make edits to the site.  I have not found why, but I have found a workaround.  I just open the service .cs file and click save.  This isn't a solution, but I no longer have to recreate the file.

  • Re: Ajax enabled WCF Service stops working with Undefined error

    04-29-2009, 10:20 PM

    It may be the free memory is too low,kill some useless processes to get more.The default minimum free memory percentage is 5.You can change it in the config file like below:

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" minFreeMemoryPercentageToActivateService="1"/>

    If you set that percentage up to 99,than 'Undefined' error will be reported again again and again.And if it happen,you can open the wcf(.svc) file in IIS.Than will show you the error details.

    Good luck!

    The 'serviceHostingEnvironment' section format:

    <serviceHostingEnvironment>
             aspNetCompatibilityEnabled="Boolean"
           minFreeMemoryPercentageToActivateService="Integer"
         <baseAddressPrefixFilters>
                    <add prefix="string"/>
              </baseAddressPrefixFilters>
         <transportConfigurationTypes>
            <add name="String" 
                 transportConfigurationType="String" />
         </transportConfigurationTypes>
    </serviceHostingEnvironment>
    Filed under:
  • Re: Ajax enabled WCF Service stops working with Undefined error

    06-25-2009, 5:59 PM
    • Member
      10 point Member
    • aaminian
    • Member since 06-15-2009, 9:50 PM
    • Posts 9

    I am having the same problem.  I have an Ajax-enabled WCF service and I get the "...'SomeService' undefined error message..."

    when I make a WCF service call from the JavaScript.  At times the problem magically goes away but not because of any changes

    I've made! 


    I have followed the development/configuration process per the MSDN article posted at http://msdn.microsoft.com/en-us/library/bb924552.aspx

    and yes the svc extension is associated with aspnet_isapi.dll, and the ScriptManager element has a reference to the svc file as well.


    This is really frustrating and I am pretty sure it is a bug (maybe in the activation of the activation of the WCF service.  What I am

    more afraid of is whether this error will show up in a production environment.

  • Re: Ajax enabled WCF Service stops working with Undefined error

    06-25-2009, 9:46 PM

    There is a bug when you include WCF service in this way:
    <asp:ScriptManager ID="ScriptManager1" runat="server">
            <services>
                <asp:servicereference Path="CostService.svc" />
            </services>
    </asp:ScriptManager>

    especially then WCF service is used in diffrent pages.
    Because the JavaScripts may be load faster then WCF services.

    Try to include your WCF service like this:
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Path="CostService.svc/js" />
    </Scripts>

    Or download the js file from "http://../CostService.svc/js" and then include like below:
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Path="CostService.js" />
    </Scripts>

    Your'd better include the other js files by ScriptManager.

    By the way, "free memory is too low" may cause this error too.

  • Re: Ajax enabled WCF Service stops working with Undefined error

    06-28-2009, 6:35 PM
    • Member
      6 point Member
    • gblume
    • Member since 03-23-2007, 7:48 PM
    • Posts 3

    I've had this intermittent problem from the start while developing on my home XP/Visual Web Developer 2008, my work Windows Server 2003/Visual Studio, and now in production, again Windows Server 2003/IIS6 - all running framework V3.5.

    Thanks for your post. What do you mean by the statement, "Your'd better include the other js files by ScriptManager."? Would you elaborate?

    Does anyone know where Microsoft stands on this? Is Microsoft not supporting WCF?

    Glenn Michael

  • Re: Ajax enabled WCF Service stops working with Undefined error

    06-28-2009, 11:23 PM

    For example,if you write javascript code in two or more .js files(not in the html file).
    wcf functions are call in these .js files.Then you can include both the scripts and
    wcf services like below:
    <asp:ScriptManager ID="ScriptManager1" runat="server" >
       <Scripts>
             <asp:ScriptReference Path="../JavaScript/public.js" />
             <asp:ScriptReference Path="../JavaScript/Js_Monitor/monitor_alarm.js" />
             <asp:ScriptReference Path="../WCF/wcfMonitor.svc/js" />
       </Scripts>
    </asp:ScriptManager>

    If not necessary don't incude the scripts file in these way:
    <head runat="server">
        <title>Wcf Service Test</title>
        <script type="text/javascript" src="../JavaScript/public.js"></script>
        <script type="text/javascript" src="../JavaScript/Js_Monitor/monitor_alarm.js"></script>
    </head>

  • Re: Ajax enabled WCF Service stops working with Undefined error

    06-29-2009, 2:15 AM
    • Contributor
      2,342 point Contributor
    • Maulik Patel
    • Member since 12-21-2007, 6:48 AM
    • Ahmedabad
    • Posts 333

    Hi rdagger,

    I am also facing same problem. Any update from your side ?

    Thanks

    Maulik Patel
    MCTS, Software Engineer

    Don't forget to click "Mark as Answer" on the post that helped you. This will give you point and help readers to know which post solved your issue and make their search easy.
Page 1 of 2 (22 items) 1 2 Next >