Ein Problem mit der AJAX-web-service-Aufruf: Microsoft JScript runtime error: Sys.Net.WebServiceFailedException:

Ich versuche, der zum aufrufen einer AJAX-web-service-Aufruf aus einer client-Website in der gleichen Maschine[Win XP Home]. Dabei bin ich immer die folgende Fehlermeldung.

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>

Unten ist die server-und 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>

(Beachten Sie, dass das aufrufen der web-service-Funktion aufrufen, die innerhalb der server funktioniert & ich habe die & service-tags richtig)

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); }
  • Wirkt sich das hinzufügen der web-service als web-Referenz im client-code tatsächlich benötigt werden wie WCF-Dienst?
InformationsquelleAutor | 2009-03-21
Schreibe einen Kommentar