Dynamic Method Binding in .NET

Dynamic Method Binding lets a Data Abstract client fetch its data through a custom server method of your own, instead of the standard GetData method that the RemoteDataAdapter calls by default.

What it does

When you call Fill on a RemoteDataAdapter, it normally invokes the service's built-in GetData method to retrieve the requested tables. Dynamic Method Binding lets you point that same adapter at a different method on your service — one you defined yourself — so your method is called instead.

Everything else on the client stays the same: the same Fill call, the same DataTables, the same data-bound grids. You are only changing which server method supplies the data, not how the client consumes it.

When to use it

Use it when the default GetData isn't enough and you need your own data-fetching method on the server — for example one that:

  • takes extra input parameters (a filter value, a mode, a tenant or customer id);
  • applies custom security or business logic before returning the data;
  • aggregates or reshapes the data in a way specific to your application.

You still get the result streamed straight back into the client's tables, with no extra client-side code.

Example

Suppose that, in order to read data from your service, you want to use a custom defined method called MyCustomGetDataMethod which takes two input parameters (DataTableNames of type StringArray, and ParameterTwo of type Integer) and returns a Binary stream.

In a code-first server, this method is declared in your service class (DataService.cs) and marked with the [ServiceMethod] attribute, so it becomes part of the published service contract:

[RemObjects.SDK.Server.ServiceMethod]
public RemObjects.SDK.Types.Binary MyCustomGetDataMethod(string[] DataTableNames, int ParameterTwo)
{
    RemObjects.DataAbstract.Server.TableRequestInfo[] requests =
        new RemObjects.DataAbstract.Server.TableRequestInfo[DataTableNames.Length];
    for (int i = 0; i < requests.Length; i++)
        requests[i] = new RemObjects.DataAbstract.Server.TableRequestInfo();
    return this.GetData(DataTableNames, requests);
}

In order for your clients RemoteDataAdapter(class) to invoke this new method (instead of the default GetData), you will need to make use of Dynamic Method Binding and modify the value of its DataRequestCall property to point to this method.

The first thing you would do is query the remote service for all the available methods by opening the drop down associated with the DataRequestCall.MethodName:

After selecting the appropriate method, the IDE designers will update the parameters contained in the DataRequestCall.Parameters collection and inform you of that through a message similar to the following:

Now you can set the DataRequestCall.OutgoingTableNamesParameter and IncomingDataParameter to the appropriate values like shown in the following screenshot:

Once these steps are complete, your RemoteDataAdapter(class) is set up. Any subsequent calls to the Fill method will invoke your custom MyCustomGetDataMethod method on the server.

Conclusion

Dynamic Method Binding keeps your client code unchanged while giving you full control over how data is fetched on the server. Instead of being limited to the predefined GetData method, you can route the adapter through any custom method that fits your scenario, and still rely on the familiar Fill/DataTable workflow on the client.

See Also

The following Data Abstract for .NET classes: