0

I am trying to invoke an AJAX web service call from a client web site in the same machine[Win XP Home]. In doing so, I am getting the following error.

Microsoft JScript runtime error: Sys.Net.WebServiceFailedException: The server method 'Greetings' failed with the following error: <html>
    <head>
        <title>Not Found</title>
        <style>
            body {font-family:"Verdana";font-weight:normal;font-size: 8pt;color:black;} 
            p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
            b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
            h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
            h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
            pre {font-family:"Lucida Console";font-size: 8pt}
            .marker {font-weight: bold; color: black;text-decoration: none;}
            .version {color: gray;}
            .error {margin-bottom: 10px;}
            .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
        </style>
    </head>
    <body bgcolor="white">

            <span><h1>Server Error in '/WebServiceClient1' Application.<hr width=100% size=1 color=silver></h1>

            <h2> <i>HTTP Error 404 - Not Found.</i> </h2></span>

            <hr width=100% size=1 color=silver>

            <b>Version Information:</b>&nbsp;ASP.NET Development Server 9.0.0.0

            </font>

    </body>
</html>

Below is the server and client code

server code:

[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. 
    [System.Web.Script.Services.ScriptService]
    public class Service : System.Web.Services.WebService
    {

        [WebMethod]
        public string Greetings(string name)
        {
            string msg;
            msg = String.Format("Hello {0}: Processed on {1}", name, System.DateTime.Now.ToLongTimeString());
            return msg;
        }
    }

client code:

<script type ="text/javascript">
    function GreetingsButtonOnClick() {
        Service.Greetings($get("NameTextBox").value, OnGreetingsComplete);
    }  //error occurs at this line and the control goes to scriptresource.axd file

    function OnGreetingsComplete(result) {
        var elem = $get("Results");
        elem.innerHTML = result;
    }
</script>

    <asp:ScriptManager ID="ScriptManager1" runat="server">
        <Services>
            <asp:ServiceReference Path="http://localhost:4033/WebService1_AJAX/Service.asmx" />
        </Services>
    </asp:ScriptManager>

(Note that invoking the web service function call within the server works fine & i have defined the & service tags properly)

js file (http://localhost:4033/WebService1_AJAX/Service.asmx/js)
--------
var Service=function() {
Service.initializeBase(this);
this._timeout = 0;
this._userContext = null;
this._succeeded = null;
this._failed = null;
}
Service.prototype={
_get_path:function() {
 var p = this.get_path();
 if (p) return p;
 else return Service._staticInstance.get_path();},
Greetings:function(name,succeededCallback, failedCallback, userContext) {
return this._invoke(this._get_path(), 'Greetings',false,{name:name},succeededCallback,failedCallback,userContext); }}
Service.registerClass('Service',Sys.Net.WebServiceProxy);
Service._staticInstance = new Service();
Service.set_path = function(value) { Service._staticInstance.set_path(value); }
Service.get_path = function() { return Service._staticInstance.get_path(); }
Service.set_timeout = function(value) { Service._staticInstance.set_timeout(value); }
Service.get_timeout = function() { return Service._staticInstance.get_timeout(); }
Service.set_defaultUserContext = function(value) { Service._staticInstance.set_defaultUserContext(value); }
Service.get_defaultUserContext = function() { return Service._staticInstance.get_defaultUserContext(); }
Service.set_defaultSucceededCallback = function(value) { Service._staticInstance.set_defaultSucceededCallback(value); }
Service.get_defaultSucceededCallback = function() { return Service._staticInstance.get_defaultSucceededCallback(); }
Service.set_defaultFailedCallback = function(value) { Service._staticInstance.set_defaultFailedCallback(value); }
Service.get_defaultFailedCallback = function() { return Service._staticInstance.get_defaultFailedCallback(); }
Service.set_path("/WebService1_AJAX/Service.asmx");
Service.Greetings= function(name,onSuccess,onFailed,userContext) {Service._staticInstance.Greetings(name,onSuccess,onFailed,userContext); }
1
  • Does adding the web service as web reference in the client code actually needed like WCF Service? Commented Mar 21, 2009 at 13:50

2 Answers 2

1

Is the Web service is a different project? If so, .NET will consider it to be a cross-domain call (I think because the client and service are running in separate instances of the developer web server) which is not supported by ASP.NET AJAX.

The simple solution is to move the service into the same project and the client that consumes it.

Sign up to request clarification or add additional context in comments.

1 Comment

Rob, I tried to do the same way as you had described but not much luck. It is C# code of ur prsntn. I would like to know how to run the web service and client simultaneouly within the same project? I ran the service in project and the client thru another browser. But it gave the same error again.
0

You have to use Method=POST. Example:

WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest,
          Method = "POST",
          RequestFormat = WebMessageFormat.Json,
          ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
public string DoMyWork()
{

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.