2010-11-03 16 views
5

estoy tratando de hacer algunas llamadas a un servicio web¿Por qué mi función CallBack no funciona?

Hice exactamente lo que se describe en este artículo

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

En cuanto a la consola de Firebug pude ver que mi función fue ejecutado y devolvió los datos esperados, pero mis funciones de devolución de llamada (OnComplete, OnError, OnTimeOut) nunca se ejecutan.

¿Cuál es el problema?

Aquí está el código (mismo código del artículo) 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; 
    } 
} 

Default.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

¿puede publicar su código aquí? eso podría ayudar a depurar el problema. –

+0

el código es EXACTAMENTE el código del artículo – Ewerton

+0

Utilicé su código exacto, devoluciones de llamada llamadas como se esperaba. Lo único que noté es que está pasando 'OnTimeOut' en lugar del parámetro' userContext', intente agregar 'InlineScript =" true "' a su referencia de servicio, luego ver fuente y verificar el script de servicio generado. –

Respuesta

1

El problema era el tipo de proyecto, funciona en la aplicación Web, no en los sitios web

+1

Me alegro de que te hayas enterado. Además, debe alejarse de los servicios ASMX y comenzar a usar WCF. –

1

Im un tipo VB sobre todo por lo que ....

Pruebe uno a la vez en orden.

Primero vea si realmente está seleccionando el cuadro de texto, lo dudo. Establezca ClientIDMode para que sea estático.

segundo intento [WebMethod(), ScriptMethod(ResponseFormat:=ResponseFormat.Json)]

Tercera hacer que el método estático .. Uy virtual y la clase también.

Cuestiones relacionadas