locked
Cannot access webservice methods via JS on all pages RRS feed

  • Question

  • User1101637354 posted

    Background:

    • Website targeting .NET 4 running through IIS on Windows 8, developed with VS 2010
    • Pages use a master page (that inherits from another master page)
    • An asmx webservice decorated with the WebService, WebServiceBinding (basic profile 1.1) and ScriptService attributes
    • Multiple pages with a <asp:ScriptManager id="scriptManager1" runat="server" EnabledPageMethods="true"></asp:ScriptManager> on.

    Problem:

    • I have a jQuery dialog representing product feedback whose HTML is in the master page in a <div>
    • Depending on a users actions this dialog will may or may not be output/rendered, if it is then a JS file is included and the dialog automatically pops open.
    • [PROBLEM] The 2 buttons on the dialog both call the same webservice method. However on some pages that have the <asp:ScriptManager> on the auto-generated JS is not included whereas other pages it is included. Obviously when it's not included clicking the buttons fails, :/

    Things I've looked at:

    • The only difference I can see between a page where the JS is included correctly and one where it is not was the use of <%@ OutputCache NoStore="true" Duration="1" VaryByParam="none" %>, so I added that to pages that didn't worked and it still doesn't work.
    • I tried cleaning the solution, rebuilding, restarting the locally hosting IIS, clearing my browsers (IE10) cache, deleting the bin and obj folders just in case VS was having one of it's moments but none of that helped.
    • After a bit of Googling I found a suggestion  that claimed that adding
    • <httpHandlers>
      	<remove verb="*" path="*.asmx"/>
      	<add verb="*" path="*.asmx"  type="System.Web.Script.Services.ScriptHandlerFactory" validate="false"/>
      </httpHandlers>
      to the system.web element would do the trick (even though it also said that .NET 4.0 should include it in the machine.config - mine didn't so I tried it out) but that didn't have any effect - although wasn't hopeful given that it works on some pages and not others.
    • I tried adding a brand new page that did not use the master page simply a form, scriptmanager and a h1 and it failed to include the relevant JS.
    • I tired setting EnabledPageMethods = "false" on the scriptmanager incase the fact the page didn't have any made it go wrong, still no luck.

    I'm am really struggling to think/Google other things to check on.

    Anybody else encounter this issue or have any thoughts on what else I might try to track down the issue would be massively appreciated.

    -- Peter

    Monday, September 30, 2013 11:03 AM

Answers

  • User1101637354 posted

    In a total Homer moment I finally found our that I was not including a service reference for my web service.

    What I hadn't realised was there was a block of code repeated (urgh! not any more as I fixed that) in every page/control that used a scriptmanager where it worked that added in the reference to the web service.

    I've been doing ASP.NET MVC projects for several years now so I'm claiming that as my defense.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 1, 2013 5:38 AM

All replies

  • User1101637354 posted

    In a total Homer moment I finally found our that I was not including a service reference for my web service.

    What I hadn't realised was there was a block of code repeated (urgh! not any more as I fixed that) in every page/control that used a scriptmanager where it worked that added in the reference to the web service.

    I've been doing ASP.NET MVC projects for several years now so I'm claiming that as my defense.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 1, 2013 5:38 AM
  • User2075212911 posted

    Hi,

    If we want to use webservice we must add the reference before.

    <asp:ScriptManager ID="ScriptManager1" runat="server" >
    
          <Services>
    
                    <asp:ServiceReference Path="WebService1.asmx" />
    
          </Services>       
    
    </asp:ScriptManager>    

    Thanks.

    Wednesday, October 2, 2013 6:24 AM