How to write a Client (.NET)

This article explains how to create a RemObjects client that connects to the server that we created in the article How to write a Remoting SDK Server (.NET).

Notes:

Adding a reference to the proxy file

For the client to invoke the remote service that we created in How to write a Remoting SDK Server (.NET), it needs a definition of its interface and methods.

We generated this information when we created the server and thus all the information we need is already included in the ROWindowsFormsServerLibrary_Intf.cs file. For the client, we just need to add a link to this file and use it.

From inside the Solution Explorer, right click the client project and select Add -> Existing Item as shown in the following screenshot:

Now browse to the location of the ROWindowsFormsServerLibrary_Intf.cs file and, by clicking the little arrow close to the Add button, select Add as Link.

Note: failing to select Add as Link by just clicking "Open" will result in a physical copy of the Intf file, which will not be automatically kept in sync with the server. Do NOT copy files but always create links to those stored in the server directory.

Adding a test button

Now double click on the Main.cs file and drop a button on the client's form as shown in this screenshot:

Double click on the button and type the following code:

private void bSum_Click(object sender, System.EventArgs e)
{
  // Creates a IROWindowsFormsServerService proxy
  ROWindowsFormsServer.IROWindowsFormsServerService myService;
  myService = ROWindowsFormsServer.CoROWindowsFormsServerService.Create(
                                                        message, clientChannel);

  // Calls the Sum method
  int myResult = myService.Sum(1,2);

  // Displays the result
  MessageBox.Show("The server returned "+myResult.ToString());
}

All done. Your client is now ready to be tested.

Compile your solution, launch both projects and click on the Sum button.

This is what you will see:

Conclusion

As you can see, the Remoting SDK makes creating remote services and clients a snap and allows you to concentrate more on your business logic.

Everything that had to do with HTTP connectivity and message encoding was done for you by the SDK and accessing a remote object is now as simple as accessing regular objects.