Creating a Client

Team-Fly    

 
.NET and COM Interoperability Handbook, The
By Alan Gordon
Table of Contents
Chapter Nine.  Using COM+(Enterprise Services)

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). Line 9 binds the default view of this dataset to a datagrid, which is a WinForms table control. Finally, lines 10 and 11 call the Dispose method on the object to free its resources immediately. It's a good idea to do this with serviced components . Calling Dispose will immediately free the unmanaged context that is associated with each serviced component.


Team-Fly    
Top
 


. Net and COM Interoperability Handbook
The .NET and COM Interoperability Handbook (Integrated .Net)
ISBN: 013046130X
EAN: 2147483647
Year: 2002
Pages: 119
Authors: Alan Gordon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net