.NET
  Home arrow .NET arrow Page 11 - .NET Remoting and Delphi
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

.NET Remoting and Delphi
By: Xavier Pacheco
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 14
    2004-08-09

    Table of Contents:
  • .NET Remoting and Delphi
  • Distributed Architectures
  • Benefits of Multitier Application Development
  • .NET Remoting Basics
  • The ChannelServices Class
  • Object Activation
  • Your First .NET Remoting Application
  • Adding References
  • BankPackage.dll: Contract Between Clients and Servers
  • Implementing the Server
  • Implementing the Client

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    .NET Remoting and Delphi - Implementing the Client


    (Page 11 of 11 )

    In the client project, the main form's uses clause contains the following namespaces:

    uses
    System.Drawing, System.Collections, System.ComponentModel,
    System.Windows.Forms, System.Data,
    // Remoting and Bank related
    BankShared,
    System.Runtime.Remoting,
    System.Runtime.Remoting.Channels,
    System.Runtime.Remoting.Channels.HTTP;

    The form's OnLoad event handler contains the following code:

    fChannel := HttpChannel.Create();
    ChannelServices.RegisterChannel(fChannel);

    fBankManager := Activator.GetObject(
      typeof(IBankManager),
      'http://localhost:8099/BankManager.soap');

    As you probably guessed, the preceding code creates an instance of the remote object BankManager, which we can now use from inside the client application.

    It is now possible to test the remote methods. Figure 29.13 shows the form of the example application that does this at design-time.

    delphi

    Figure 29.13
    Main form of Client application.

    The Refresh button's Click event handler contains code shown in Listing 29.4.

    Listing 29.4 Refresh Button's Click Event Handler

    1.  procedure TWinForm2.bRefresh_Click(sender: System.Object;
    2.      e: System.EventArgs);
    3.  var accountarray : TAccountNumberArray;
    4.    i : integer;
    5.  begin
    6.   accountarray := fBankManager.GetAccountNumbers;
    7.   cbBankAccounts.Items.Clear;
    8.   cbOrigin.Items.Clear;
    9.   cbDestination.Items.Clear;
    10.
    11.  for i := 0 to High(accountarray) do begin
    12.   cbBankAccounts.Items.Add(accountarray[i].ToString);
    13.   cbOrigin.Items.Add(accountarray[i].ToString);
    14.   cbDestination.Items.Add(accountarray[i].ToString);
    15.  end;
    16.  cbBankAccounts.SelectedIndex := 0;
    17. end;


    Find the code on the CD: \Code\Chapter29\Ex01.


    As you can see from the first line of this method, the use of the remote object pointed by fBankManager is not any different from using a local copy. We declared a variable of type TAccountNumberArray at line 3, and we use it at line 6.

    Keep in mind that the similarities end at the code level, especially when it comes to performance.

    When the code

    accountarray := fBankManager.GetAccountNumbers;

    is executed, the client application is creating a SOAP message, sending it to the server via HTTP and unpacking the response. This overhead is not obvious when making a single method call, but you will immediately see a big difference in performance as soon as you put that code inside a loop.

    The Retrieve button's Click event handler contains the code shown in Listing 29.5.

    Listing 29.5 Retrieve Button's Click Event Handler

    1.  procedure TWinForm2.bRetrieve_Click(sender: System.Object;
    2.   e: System.EventArgs);
    3.  var acctnumber : integer;
    4.    account : TAccount;
    5.  begin
    6.   acctnumber := System.Convert.ToInt32(cbBankAccounts.Text);
    7.   account := fBankManager.GetAccount(acctnumber);
    8.   tbAcctNumber.Text := account.Number.ToString;
    9.   tbAcctName.Text := account.Name;
    10.   tbAcctBalance.Text := account.Balance.ToString;
    11.  end;


    Find the code on the CD: \Code\Chapter29\Ex01.


    At line 6, we grab the selected account number from the combo box cbBankAccounts and assign it to the integer variable acctnumber. We then pass acctnumber to the BankManager.GetAccount method (line 7), which will generate a remote call to the BankManager object running on the server. Finally (lines 8–10), we display the information contained in the account returned by the server.

    Finally, the Transfer button's Click event handler contains

    procedure TWinForm2.bTransfer_Click(sender: System.Object;
    e: System.EventArgs);
    var originacct_acct, destination_acct : integer;
      amount : double;
    begin
    originacct_acct := System.Convert.ToInt32(cbOrigin.Text);
    destination_acct := System.Convert.ToInt32(cbDestination.Text);
    amount := System.Convert.ToDouble(tbAmount.Text);
    fBankManager.TransferMoney(originacct_acct,
                   destination_acct,
                   amount);
      MessageBox.Show('Transfer completed');
    end;

    The client, when launched, displays the form shown in Figure 29.14.

    delphi

    Figure 29.14
    Client application—remoting in action.

    This chapter is from Delphi for .NET Developer's Guide, by Xavier Pacheco (Sams, 2004, ISBN: 0-672-32443-1). Check it out at your favorite bookstore today.

    Buy this book now.

     


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · in time compiling is message:Incompatible types 'IBankManager' and 'Object'where...
       · is in WinformfBankManager := Activator.GetObject( typeof(IBankManager), ...
     

    .NET ARTICLES

    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC
    - The Windows Ribbon Framework
    - Markup Language for the Ribbon Framework
    - Visually Upgrade Your MFC Project
    - New Features for the Statusbar in MFC
    - Working with the Statusbar in MFC
    - Iron Speed Design v60 Review
    - Binary and XML Serialization
    - Using CrystalReportViewer to Display Crystal...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek