1 / 21

Windows Application

Windows Application. Same Application Domain. Database. GUI. Classes. Modules. Thr e e-Tier Architecture. GUI. Business Logic. Database. Host. Logic. Different Application Domains. Client and Server. Client Windows Programs (normally) Server

Download Presentation

Windows Application

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Windows Application Same Application Domain Database GUI Classes Modules

  2. Three-Tier Architecture GUI Business Logic Database Host Logic Different Application Domains

  3. Client and Server • Client Windows Programs (normally) • Server Programs over network or Internet (normally) Mainframe, Unix, Linux, Gamma: Windows 2005 Server

  4. SOAP (Simple Object Access Protocol) Different Systems Heavyweight Data Conversion Integer, 2 bytes Little-Endian Big-Endian ASCII characters

  5. .NET Remoting Both client and server are Windows Lightweight Accessing objects across application domains

  6. Basic Concepts • Channel TCP and HTTP • Ports • Proxy Used on the client side to make calls into the remote object .NET handles it for us • Register object with the Remoting subsystem Class, Url, Singleton/SingleCall

  7. Remoting Objects • Singleton (wellknown) One object for all requests Used in most cases • SingleCall (wellknown) One object for each request • Activated Available only for the client • Serializable Copied over between machines

  8. Example Server Solution • Project MyServer • Project MyObjects Client Solution • Project Prog7 • Project FormGrid

  9. Project MyObjects ‘ Class library shared by both server and client Public Class Customers Inherits MarshalByRefObject ' The object stays in the server domain Dim ranNum As New Random ... End Class Root Name Space: UWPCS3340

  10. Project MyObjects Public Class Customers ... Public Sub New() Debug("Created") End Sub Protected Overrides Sub Finalize() Debug("Finalized") MyBase.Finalize() End Sub Protected Sub Debug(ByVal buf As String) Console.WriteLine("[" & Me.GetHashCode & "] " & buf) End Sub Public Function CreateCustomer() As String ‘ could be any type Dim CustomerID As String = ranNum.Next(1000).ToString & _ ": from host " & IPAddress.ToString Debug("Created Customer #" & CustomerID) Return CustomerID End Function End Class

  11. Project MyServer ‘ Console application ‘ May need to add references to the following namespace ‘ add reference to System.Runtime.Remoting Imports UWPCS3340 Imports System.Runtime.Remoting Imports System.Runtime.Remoting.Channels Imports System.Runtime.Remoting.Channels.Tcp

  12. Project MyServer Module Module1 Dim IPAddress As System.Net.IPAddress Dim theHost As String Dim IPHEntry As System.Net.IPHostEntry Sub Main() theHost = System.Net.Dns.GetHostName IPHEntry = System.Net.Dns.GetHostEntry(theHost) IPAddress = IPHEntry.AddressList(0) ' Registers channel ChannelServices.RegisterChannel(New TcpServerChannel(8081), False) Console.WriteLine("Server " & theHost & " at IP address " & IPAddress.ToString) Console.WriteLine() Dim Url As String = "MyUrl" Console.WriteLine("Registering: " & GetType(Customers).ToString) Console.WriteLine("URI: " & Url) RemotingConfiguration.RegisterWellKnownServiceType( _ GetType(Customers), "MyUrl", WellKnownObjectMode.Singleton) Console.WriteLine("Registered: " & GetType(Customers).ToString) ‘ Reads a line to terminate Console.ReadLine() End Sub End Module

  13. Project MyClient ‘ Windows Application ‘ Add reference to MyObjects.dll Imports UWPCS3340 Dim url As String Dim theCustomer As MyObjects.Customers Private Sub Form1_Load(...) rdoLocal.Checked = True End Sub Private Sub rdoLocal_CheckedChanged(…) rdoLocal.CheckedChanged If rdoLocal.Checked Then ' Port 49341 works! url = "tcp://localhost:49341/MyUrl“ ElseIf rdoGamma.Checked Then ' Port 8081 works too! url = "tcp://137.104.21.2:8081/MyUrl“ ' IP address and DNS name both work! ‘ url = "tcp://gamma.uwplatt.edu:8081/MyUrl“ End If theCustomer = CType(Activator.GetObject(GetType(Customers), url), Customers) End Sub

  14. Project MyClient ‘ Call class method that is a function returning a string Private Sub Button1_Click() Handles Button1.Click Dim theID As String Try theID = theCustomer.CreateCustomer() txtLog.Text &= "The customer ID: " & theID & vbCrLf txtLog.SelectionStart = txtLog.Text.Length - 1 txtLog.ScrollToCaret() Catch ex As Exception MsgBox(ex.Message) Thread.Sleep(5000) Exit Sub End Try End Sub

  15. Project MyObjects Public Class Customers ... Public Function PassParams(ByVal count As Integer, ByVal command As String) As String Dim answer As String answer = Math.Sqrt(Math.Abs(count)).ToString & ";" & command & _ ";IP Address: " & IPAddress.ToString Return answer End Function End Class

  16. Project MyClient ‘ Call class method that is a function with two paramters Private Sub Button2_Click() Handles Button2.Click Dim theParams As String Try theParams = theCustomer.PassParams(2, "Bid") txtLog.Text &= "The customer ID: " & theParams & vbCrLf txtLog.SelectionStart = txtLog.Text.Length - 1 txtLog.ScrollToCaret() Catch ex As Exception MsgBox(ex.Message) Thread.Sleep(5000) Exit Sub End Try End Sub

  17. Project MyObjects Public Class Customers ... ‘ Returns an array Public Function getArray() As String() Dim theArray(3) As String theArray(0) = "SA" theArray(1) = "HK" theArray(2) = "DQ" theArray(3) = "CJ" Return theArray End Function End Class

  18. Project MyObjects <Serializable()> _ Public Structure theMessage Dim singleVaye As Single Dim intValue As Integer Dim strValue As String End Structure Public Class Customers ‘ Returns a structure Public Function getStruct () As theMessage Dim struct As theMessage struct.singleVaye = 90.5 struct.intValue = 45 struct.strValue = "Structure“ Return theArray End Function End Class

  19. Project MyObjects <Serializable()> _ Public Structure theMessage ... Dim theArray() As String ‘ Cannot specify size. Pointer. End Structure Public Class Customers ‘ Returns a structure with an array Public Function getStruct () As theMessage Dim struct As theMessage Dim theArray(3) As String ... theArray(0) = "SA" theArray(1) = "HK" theArray(2) = "DQ" theArray(3) = "CJ" struct.theArray = theArray Return theArray End Function End Class

  20. Project MyObjects Public Class Customers ‘ Reference parameters Public Function RefParams(ByRef x As Integer) As theMessage Dim struct As theMessage Dim theArray(4) As String x += 1 ... theArray(0) = "SA" theArray(1) = "HK" theArray(2) = "DQ" theArray(3) = "CJ" struct.theArray = theArray Return theArray End Function End Class

  21. Project MyObjects Public Class Customers ‘ Returns an object (DataTable) Public Function RefObj() As DataTable Dim theTable As New DataTable ... Return theTable End Function End Class

More Related