0

I have a Datasnap Server and i need consuming the data with a windows phone.

The TSituacaoProxy class, when i sends a parameter (Id), the return must be a JSON object.

But the error is shown:

Object reference not set to an instance of an object.

My Code:

 private void clique(object sender, RoutedEventArgs e)
    {

        DSRESTConnection connection = new DSRESTConnection();
        connection.setHost("10.0.0.10");
        connection.setPort(8080);
        connection.setProtocol("http");
        connection.setUserName("master");
        connection.setPassword("C28861C83BD5397187FD55D04C2547F9");
        connection.setContext("datasnap/REST");

        DSProxy.TSituacaoProxy Proxy = new DSProxy.TSituacaoProxy(connection, ExceptionCallback);
        TJSONObject jObject = TJSONObject.Parse("22");

        Proxy.Loader(jObject, (TJSONObject Result) =>
        {
            MessageBox.Show(Result.ToString()); 

        }, ExceptionCallback);

    }


    public void ExceptionCallback(Exception e)
    {
        MessageBox.Show(e.Message);
    }

TSituacaoProxy class:

public class TSituacaoProxy : DSAdmin
{
  public TSituacaoProxy(DSRESTConnection Connection, ExceptionCallback ExCal)
      : base(Connection, ExCal)
  {
  }

  private DSRESTParameterMetaData[] TSituacaoProxy_teste_Metadata;
  private DSRESTParameterMetaData[] get_TSituacaoProxy_teste_Metadata()
  {
    if (TSituacaoProxy_teste_Metadata == null)
    {
      TSituacaoProxy_teste_Metadata = new DSRESTParameterMetaData[]
      {
        new DSRESTParameterMetaData("xValue", DSRESTParamDirection.Input, DBXDataTypes.WideStringType, "string"),
        new DSRESTParameterMetaData("", DSRESTParamDirection.ReturnValue, DBXDataTypes.WideStringType, "string"),
      };
    }
    return TSituacaoProxy_teste_Metadata;
  }

The Loader method:

public delegate void LoaderCallback(TJSONObject Result);

  public void Loader(TJSONObject xId, LoaderCallback callback = null, ExceptionCallback ExCal = null)
  {
    DSRESTCommand cmd = getConnection().CreateCommand();
    cmd.setRequestType(DSHTTPRequestType.POST);
    cmd.setText("TSituacaoProxy.Loader");
    cmd.prepare(get_TSituacaoProxy_Loader_Metadata());
    InternalConnectionDelegate LoaderDel = () =>
    {
      if (callback != null)
      {
        try
        {
          callback.DynamicInvoke((TJSONObject)cmd.getParameter(1).getValue().GetAsJSONValue());
        }
        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().SetAsJSONValue(xId);
    getConnection().execute(cmd, this, LoaderDel, ExCal);
  }
  private DSRESTParameterMetaData[] TSituacaoProxy_Select_Metadata;
  private DSRESTParameterMetaData[] get_TSituacaoProxy_Select_Metadata()
  {
    if (TSituacaoProxy_Select_Metadata == null)
    {
      TSituacaoProxy_Select_Metadata = new DSRESTParameterMetaData[]
      {
        new DSRESTParameterMetaData("xAssorts", DSRESTParamDirection.Input, DBXDataTypes.JsonValueType, "TJSONArray"),
        new DSRESTParameterMetaData("", DSRESTParamDirection.ReturnValue, DBXDataTypes.JsonValueType, "TJSONArray"),
      };
    }
    return TSituacaoProxy_Select_Metadata;
  }
JoelC
  • 3,664
  • 9
  • 33
  • 38
Rene Sá
  • 4
  • 3
  • 23
  • [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Soner Gönül Aug 25 '14 at 13:47
  • But the connection fails to be established, how the response is null? – Rene Sá Aug 25 '14 at 14:15

1 Answers1

0

change code in dsrestconnection.cs

this

        HttpWebRequest Client = (HttpWebRequest)WebRequest.Create(URL + "?" + DateTime.Now.Ticks.ToString());

to this

HttpWebRequest Client =(HttpWebRequest)WebRequestCreator.ClientHttp.Create(new Uri(URL + "?" + DateTime.Now.Ticks.ToString()));