WebService - ServerMethod not found ?!

Last post 05-08-2008 9:02 PM by gt1329a. 7 replies.

Sort Posts:

  • WebService - ServerMethod not found ?!

    04-09-2008, 9:34 AM

    Hello there,

    i need help: I have a simple WebService for test purposes called "WebService.asmx", and in the same folder a WebForm called "Test.aspx". What they look like:

    WebService:

    using System;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Web.Script.Services;

    namespace MatCodeWS
    {
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [ScriptService()]
        public class WebService : System.Web.Services.WebService
        {
            [WebMethod]
            public string HelloWorld()
            {
                return "
    Hello World";
            }
        }
    }

     aspx File:   

    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" Title="Untitled Page" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    
    <input style="position: absolute; left: 450px;" type="button" onclick="sayHelloWorld()" />  
    
        <asp:ScriptManager id="ScriptManager1" runat="server">
            <Services>
                <asp:ServiceReference Path="WebService.asmx" />
            </Services>
        </asp:ScriptManager>
    
        <script language="javascript" type="text/javascript">
        
        function sayHelloWorld()
        {            
            MatCodeWS.WebService.HelloWorld(Succeeded);
        }
        
        function Succeeded(result,eventargs)
        {
            alert(result);
        }    
        </script>
    </asp:Content>

    Clicking on the input button results in a big alert box containing HTML code. Title: "Server Method 'HelloWorld failed with the following error:'" Then there is a bunch of HTML Code and in between you can read phrases like "HTTP-Error 404 - Not found" etc.

     Anyone a hint ?

    thanks a lot

  • Re: WebService - ServerMethod not found ?!

    04-09-2008, 9:48 PM
    • Loading...
    • gt1329a
    • Joined on 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 1,606
    Try changing the ServiceReference's Path to ~/WebService.asmx (or whatever is correct).
    Encosia - ASP.NET, AJAX, and more.

    Latest article: The Future of ASP.NET AJAX
  • Re: WebService - ServerMethod not found ?!

    04-10-2008, 1:52 AM

    No, does not change anything :(

  • Re: WebService - ServerMethod not found ?!

    04-10-2008, 2:13 AM
    • Loading...
    • gt1329a
    • Joined on 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 1,606
    Are you absolutely sure you have the path to the web service correct?  Can you access it directly in the browser at the URL you're using?
    Encosia - ASP.NET, AJAX, and more.

    Latest article: The Future of ASP.NET AJAX
  • Re: WebService - ServerMethod not found ?!

    04-10-2008, 9:24 AM
    • Loading...
    • bcanonica
    • Joined on 12-08-2006, 9:11 PM
    • Philadelphia, PA
    • Posts 291
    Move your asmx code above into a web service class in the App_Code folder.  Then have your asmx file only have the following line of code below.  This is how you are able to reference the service.  In vs2008 you will even get intellisense for it!!!   

    <%@ WebService Language="C#" CodeBehind="~/App_Code/WebService.cs" Class="MatCodeWS.WebService" %>

    Remember to mark any post that is helpful as an answer and change posts status to Resolved to help others in the future.

    cheers,

    BC

    http://voidimpossible.com
  • Re: WebService - ServerMethod not found ?!

    04-15-2008, 4:36 AM
    Answer

    Hi, 

    To enable an .asmx Web service to be called from client script in an ASP.NET Web page, you first add a ScriptManager control to the page. You reference the Web service by adding an asp:ServiceReference child element to the ScriptManager control and setting its path attribute to point to the Web service. The ServiceReference object instructs ASP.NET 2.0 AJAX Extensions to generate a JavaScript proxy class for calling the specified Web service from client script.

    The following example shows how to enable a Web service named SimpleWebService.asmx to be called from script in an ASP.NET Web page.

    <asp:ScriptManager runat="server" ID="scriptManager">
    <Services>
    <asp:ServiceReference
    path="~/WebServices/SimpleWebService.asmx" />
    </Services>
    </asp:ScriptManager>

    The ServiceReference object can reference a Web service only in the same domain. The Web service path can be relative, application relative, domain relative, or absolute. For absolute paths, you must make sure that the path is in the same domain.

     

    If you have further questions, let me know! 

    Best Regards,

    Sincerely,
    Jin-Yu Yin
    Microsoft Online Community Support
  • Re: WebService - ServerMethod not found ?!

    05-08-2008, 8:41 PM
    • Loading...
    • Zenuke
    • Joined on 10-18-2006, 1:28 PM
    • Posts 158

    What if you are using a masterpage?

     I can do this in a normal page, but as soon as I try to use a master page this no longer works.

  • Re: WebService - ServerMethod not found ?!

    05-08-2008, 9:02 PM
    • Loading...
    • gt1329a
    • Joined on 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 1,606
    Add a ScriptManagerProxy to the content page, then add the service there.
    Encosia - ASP.NET, AJAX, and more.

    Latest article: The Future of ASP.NET AJAX
Page 1 of 1 (8 items)