0

I'm having a tough time with the following problem, if some one has any idea how to make it work i would realy appreciate it.

As I,m calling an actionresult from a jquery function, that has a callback function

as you can see here.

function SayHello() {

    var user = CaptureElements();
    var json = JSON.stringify(usuario);       
    var url = '@Url.Action("SayHello", "User")';
    $("#divLoading").show();

    $.ajax(
        {
            url: url,
            type: 'POST',
            dataType: 'json',
            data: json,
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                $("#aaa")[0].innerHTML = data;
                $("#divLoading").hide();                   
            }
        });
}

function CaptureElements() {        
    var FisrtName = document.getElementById("txtNome").value;
    var LastName = document.getElementById("txtLastName").value;        
    return (name == "" ? null : { name: name, lastName: lastName,})

}

this is my ActionResult.

[HttpPost]
public ActionResult SayHello(User usr)
    {
        var hello = "";
        var Proxy = conection();
        Proxy.SayHello(usr.FisrtName.ToString(), usr.LastName.ToString(),
            (String Result) =>
            {
                hello = Result;                   
            }, ExceptionCallback);

        return Json(hello, JsonRequestBehavior.AllowGet);
}

public void ExceptionCallback(Exception e)
    {
        //...

    }

so the problem is, being a call back function "hello" returns null first and then it goes to the actual function,

This code (DSProxy.cs Class) was created from a Delphi xe5 on data snap rest Mobile server to c# silverligth, and im trying to use it with mvc4.

/**
* @param FirstName [in] - Type on server: string
* @param LastName [in] - Type on server: string
* @return result - Type on server: string
*/
  public delegate void SayHelloCallback(String Result);

  public void SayHello(String FirstName, String LastName, SayHelloCallback callback = null, ExceptionCallback ExCal = null)
  {
    DSRESTCommand cmd = getConnection().CreateCommand();
    cmd.setRequestType(DSHTTPRequestType.GET);
    cmd.setText("TServerMethods1.SayHello");
    cmd.prepare(get_TServerMethods1_SayHello_Metadata());
    InternalConnectionDelegate SayHelloDel = () =>
    {
      if (callback != null)
      {
        try
        {
          callback.DynamicInvoke(cmd.getParameter(2).getValue().GetAsString());
        }
        catch (Exception ex)
        {
          if (ExCal != null) getConnection().syncContext.Send(new SendOrPostCallback(x => ExCal.DynamicInvoke(ex.InnerException)), null);
          else getConnection().syncContext.Send(new SendOrPostCallback(x => BaseExCal.DynamicInvoke(ex.InnerException)), null);
        }
      }
    };
    cmd.getParameter(0).getValue().SetAsString(FirstName);
    cmd.getParameter(1).getValue().SetAsString(LastName);
    getConnection().execute(cmd, this, SayHelloDel, ExCal);
  }

thanks in advance

I was succesfull using windowsform with a message box, even populated a grid and stuff.

private void button1_Click(object sender, EventArgs e)
{
     var Proxy = conexao();

      Proxy.SayHello(txtName.Text, txtLastName.Text,(String Result) =>
        {
            MessageBox.Show(Result);
        }, ExceptionCallback);  
    }
2
  • You should look into setting up a websocket in order to use this callback approach. signalr is a very easy integration into mvc
    – Travis J
    May 14, 2014 at 20:59
  • i was successful using windowsform...
    – Marisco
    May 15, 2014 at 12:41

1 Answer 1

2

We figured that the proxy class created by delphi its used for non web apps, so we actualy just doing a request using HttpClient Class instead. thanks all!

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.