حاولت اعمل web server يحسب جمع رقمين بالاعتماد على كتاب dot net remoting للاخ crazy -man
وهذا كود الويب سيرفر
Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Class Main
Public Shared Sub Main()
Try
Dim Channel As TcpChannel = New TcpChannel(1060)
ChannelServices.RegisterChannel(Channel)
RemotingConfiguration.RegisterWellKnownServiceType(GetType(IRemotingOperation.IRemotingOperation), "RemotingOperation", WellKnownObjectMode.Singleton)
Console.WriteLine("The server is started correctlly")
Console.ReadLine()
Catch ex As Exception
Console.WriteLine("The server doesn't started correctlly")
Console.ReadLine()
End Try
End Sub
End Classوهذا كو العمليات الي يقوم به web server
Public Class Op
Inherits MarshalByRefObject
Implements IRemotingOperation.IRemotingOperation
Dim Value As Integer
Public Overrides Function InitializeLifetimeService() As Object
Return Nothing
End Function
Public Function Addition(ByVal a As Integer, ByVal b As Integer) As Integer Implements IRemotingOperation.IRemotingOperation.Addition
Console.WriteLine(String.Format("Calling Addition Function:a={0},b={1}", a, b))
Return a + b
End Function
Public Function Incrementation(ByVal Number As Integer) As Integer Implements IRemotingOperation.IRemotingOperation.Incrementation
Console.WriteLine(String.Format("Calling Incrementation()Function: Valeur ={0}", Number))
Value = Value + Number
Return Value
End Function
End Classوهذا كود الفرو م
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Public Class Form1
Dim RemoteInterfaces As IRemotingOperation.IRemotingOperation
Public Sub open()
InitializeComponent()
Try
Dim channel As TcpChannel = New TcpChannel
ChannelServices.RegisterChannel(channel)
RemoteInterfaces = (Activator.GetObject(GetType(IRemotingOperation.IRemotingOperation), "tcp://localhost:1060/RemotingOperation"))
Catch ex As Exception
MsgBox("Error while trying connecting with server !!")
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'
'Add
'
open()
Dim r As String
Try
If RemoteInterfaces IsNot Nothing Then
TextBox3.Text = RemoteInterfaces.Addition(Val(TextBox1.Text), Val(TextBox2.Text)).ToString()
End If
Catch ex As Exception
r = ex.Message
MsgBox(r)
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'
'In
'
open()
Dim r As String
Try
If RemoteInterfaces IsNot Nothing Then
TextBox5.Text = RemoteInterfaces.Incrementation(Val(TextBox4.Text)).ToString()
End If
Catch ex As Exception
r = ex.Message
MsgBox(r)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'
'Load
'
End Sub
End Classطبعا في كلاس للعمليات
Public Interface IRemotingOperation Function Addition(ByVal a As Integer, ByVal b As Integer) As Integer Function Incrementation(ByVal Number As Integer) As Integer End Interface
هلا الخطاء هو التالي