2010-11-03 25 views
5

Próbuję zrobić kilka połączeń do WebServiceDlaczego funkcja CallBack nie działa?

Zrobiłem dokładnie to, co jest opisane w tym artykule

http://viralsarvaiya.wordpress.com/2010/03/23/calling-web-service-from-java-script-in-asp-net-c/

Patrząc na konsoli Firebug widziałem, że moja funkcja została wykonana i zwrócił oczekiwane dane, ale moje funkcje wywołania zwrotnego (OnComplete, OnError, OnTimeOut) nigdy nie są wykonywane.

Co jest nie tak?

Oto kod (ten sam kod artykułu) Service.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Services; 

[WebService(Namespace = "http://Localhost...xys/")] 
[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] 

[System.Web.Script.Services.ScriptService()] 

public class Service : System.Web.Services.WebService 
{ 
    public Service() { 

    //Uncomment the following line if using designed components 
    //InitializeComponent(); 
    } 

    [WebMethod] 
    public string HelloWorld(string strNoOfData) 
    { 
     return strNoOfData; 
    } 
} 

Defalult.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title></title> 
<script type="text/javascript" language="javascript"> 
function CallService() { 
    Service.HelloWorld(document.getElementById('Textbox1').value, 
     OnComplete, OnError, OnTimeOut); 
} 

function OnComplete(Text) { 
    alert(Text); 
} 

function OnTimeOut(arg) { 
    alert("timeOut has occured"); 
} 

function OnError(arg) { 
    alert("error has occured: " + arg._message); 
} 
</script> 
</head> 
<body> 
<form id="form1" runat="server"> 
<div> 
<asp:ScriptManager ID="ScriptManager1" runat="server"> 
    <Services> 
     <asp:ServiceReference Path="~/Service.asmx" /> 
    </Services> 
</asp:ScriptManager> 

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server"> 
<ContentTemplate> 
<fieldset> 
<asp:TextBox ID="Textbox1" runat="server"></asp:TextBox> 
<br /> 
<asp:Button ID="Button1" runat="server" Text="Call Service" OnClientClick="CallService()" /> 
</fieldset> 
</ContentTemplate> 
</asp:UpdatePanel> 
</div> 
</form> 
</body> 
</html> 
+0

czy możesz wysłać tutaj swój kod? to może pomóc w debugowaniu problemu. –

+0

Kod to DOKŁADNIE kod artykułu – Ewerton

+0

Użyłem twojego dokładnego kodu, callbacki są wywoływane zgodnie z oczekiwaniami. Jedyne, co zauważyłem, to przekazywanie 'OnTimeOut' zamiast parametru' userContext', spróbuj dodać 'InlineScript =" true "' do referencji do usługi, następnie wyświetl źródło i sprawdź wygenerowany skrypt usługi. –

Odpowiedz

1

Problemem był typ projektu, działa on w aplikacji WWW, a nie w WebSites

+1

Cieszę się, że się dowiedziałeś. Powinieneś także odejść od usług ASMX i zacząć korzystać z WCF. –

1

Im VB facet przeważnie tak ....

Spróbuj jeden po drugim w kolejności.

Najpierw sprawdź, czy naprawdę zaznaczasz pole tekstowe, wątpię w to. Ustaw parametr ClientIDMode na statyczny.

drugie spróbować [WebMethod(), ScriptMethod(ResponseFormat:=ResponseFormat.Json)]

trzecich wnoszą metoda statyczna .. oops wirtualny i klasy także.

Powiązane problemy