Creating a Client

Now that you have created a serviced component, you can use it in much the same way as you would use any other managed class. The following code shows how you would use the Book class.

1.  private void cmdGetData_Click(object sender,
2.  System.EventArgs e)
3.  {
4.      Book obj;
5.      IDisposable disp;
6.      DataSet ds;
7.      obj=new Book();
8.      ds=obj.GetBooksByTitle(txtTitle.Text);
9.      grid1.DataSource=ds.Tables["Titles"].DefaultView;
10.     disp=obj as IDisposable;
11.       disp.Dispose();
12.  }

In this code, you instantiate an instance of the Book class on line 7. Line 8 calls the GetBooksByTitle, passing in the title of a book (or a portion of the title). This method will return an ADO.NET dataset (we'll talk more about ADO.NET and datasets shortly). ...

Get .NET and COM Interoperability Handbook, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.