Question

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);  
    }
Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top