mkumar@deseinindure.com
New member
- Joined
- Aug 7, 2010
- Messages
- 1
- Programming Experience
- 3-5
I am new to .NET remoting. I have a windows forms based application already developed. The application has been developed in VB.net 2005 and works fine when installed on a client machine. However I want to have a small client program that connects to a remote server and runs the application at the server.
Can we do it? I have tried it by downloading some sample code and customizing it as follows but without any success
ServiceClass.vb (Remote Class)
Imports System
Imports System.Runtime.Remoting
Imports System.Web
Imports System.Windows.Forms
Imports TestRemoteServerForm
Public Interface IService
Function GetServerTime() As DateTime
Function GetServerString() As String
Sub LoadForm()
End Interface
Public Class ServiceClass
Inherits MarshalByRefObject
Implements IService
Private InstanceHash As Integer
Public Sub New()
InstanceHash = Me.GetHashCode()
End Sub
Public Function GetServerTime() As Date Implements IService.GetServerTime
Return DateTime.Now
End Function
Public Function GetServerString() As String Implements IService.GetServerString
' Use the HttpContext to acquire what IIS thinks the client's identity is.
Dim temp As String = HttpContext.Current.User.Identity.Name
If (temp Is Nothing Or temp.Equals(String.Empty)) Then
temp = "**unavailable**"
End If
Return "Hi there. You are being served by instance number: " _
& InstanceHash.ToString() _
& ". Your alias is: " _
& temp
End Function
Public Sub LoadForm() Implements IService.LoadForm
Dim NewForm As Form
NewForm = New TestRemoteServerForm.Form1
NewForm.Show()
End Sub
End Class
web.config
<configuration>
<connectionStrings>
<add name="billing" connectionString="Data Source=ho;Persist Security Info=True;User ID=billing;Password=billing;Unicode=True" />
</connectionStrings>
<system.runtime.remoting>
<application>
<service>
<wellknown
mode="SingleCall" objectUri="SAService.rem"
type="ServiceClass, ServiceClass"/>
</service>
<channels>
<channel ref="http"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>
From VS2005 Command prompt
vbc /t:library /r:TestRemoteServerForm.dll ServiceClass.vb
Client.vb (client class)
Imports System
Imports System.Collections
Imports System.Net
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Security.Principal
Public Class Client
Public Shared Sub Main()
RemotingConfiguration.Configure("Client.exe.config", False)
Dim service As ServiceClass = New ServiceClass()
Dim Props As IDictionary = ChannelServices.GetChannelSinkProperties(service)
Props.Item("credentials") = CredentialCache.DefaultCredentials
service.LoadForm()
End Sub
End Class
Client.exe.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="http" useDefaultCredentials="true" port="0">
<clientProviders>
<formatter
ref="binary"
/>
</clientProviders>
</channel>
</channels>
<client>
<wellknown
url="http://localhost:80/HttpBinary/SAService.rem"
type="ServiceClass, ServiceClass"
/>
</client>
</application>
</system.runtime.remoting>
</configuration>
From VS2005 Command prompt
vbc /r:System.Runtime.Remoting.dll Client.vb
Both ServiceClass.vb and Client.vb get compiled successfully and IIS is configured
However when I run Client.exe from command prompt, I get follwoing error
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or ass
embly 'TestRemoteServerForm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nu
ll' or one of its dependencies. The system cannot find the file specified.
File name: 'TestRemoteServerForm, Version=1.0.0.0, Culture=neutral, PublicKeyTok
en=null'
Server stack trace:
at ServiceClass.LoadForm()
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(
IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInCont
ext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(R
untimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fE
xecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMes
sage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
at ServiceClass.LoadForm()
at Client.Main()
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\M
icrosoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure lo
gging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fus
ion!EnableLog].
Can we do it? I have tried it by downloading some sample code and customizing it as follows but without any success
ServiceClass.vb (Remote Class)
Imports System
Imports System.Runtime.Remoting
Imports System.Web
Imports System.Windows.Forms
Imports TestRemoteServerForm
Public Interface IService
Function GetServerTime() As DateTime
Function GetServerString() As String
Sub LoadForm()
End Interface
Public Class ServiceClass
Inherits MarshalByRefObject
Implements IService
Private InstanceHash As Integer
Public Sub New()
InstanceHash = Me.GetHashCode()
End Sub
Public Function GetServerTime() As Date Implements IService.GetServerTime
Return DateTime.Now
End Function
Public Function GetServerString() As String Implements IService.GetServerString
' Use the HttpContext to acquire what IIS thinks the client's identity is.
Dim temp As String = HttpContext.Current.User.Identity.Name
If (temp Is Nothing Or temp.Equals(String.Empty)) Then
temp = "**unavailable**"
End If
Return "Hi there. You are being served by instance number: " _
& InstanceHash.ToString() _
& ". Your alias is: " _
& temp
End Function
Public Sub LoadForm() Implements IService.LoadForm
Dim NewForm As Form
NewForm = New TestRemoteServerForm.Form1
NewForm.Show()
End Sub
End Class
web.config
<configuration>
<connectionStrings>
<add name="billing" connectionString="Data Source=ho;Persist Security Info=True;User ID=billing;Password=billing;Unicode=True" />
</connectionStrings>
<system.runtime.remoting>
<application>
<service>
<wellknown
mode="SingleCall" objectUri="SAService.rem"
type="ServiceClass, ServiceClass"/>
</service>
<channels>
<channel ref="http"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>
From VS2005 Command prompt
vbc /t:library /r:TestRemoteServerForm.dll ServiceClass.vb
Client.vb (client class)
Imports System
Imports System.Collections
Imports System.Net
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Security.Principal
Public Class Client
Public Shared Sub Main()
RemotingConfiguration.Configure("Client.exe.config", False)
Dim service As ServiceClass = New ServiceClass()
Dim Props As IDictionary = ChannelServices.GetChannelSinkProperties(service)
Props.Item("credentials") = CredentialCache.DefaultCredentials
service.LoadForm()
End Sub
End Class
Client.exe.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="http" useDefaultCredentials="true" port="0">
<clientProviders>
<formatter
ref="binary"
/>
</clientProviders>
</channel>
</channels>
<client>
<wellknown
url="http://localhost:80/HttpBinary/SAService.rem"
type="ServiceClass, ServiceClass"
/>
</client>
</application>
</system.runtime.remoting>
</configuration>
From VS2005 Command prompt
vbc /r:System.Runtime.Remoting.dll Client.vb
Both ServiceClass.vb and Client.vb get compiled successfully and IIS is configured
However when I run Client.exe from command prompt, I get follwoing error
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or ass
embly 'TestRemoteServerForm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nu
ll' or one of its dependencies. The system cannot find the file specified.
File name: 'TestRemoteServerForm, Version=1.0.0.0, Culture=neutral, PublicKeyTok
en=null'
Server stack trace:
at ServiceClass.LoadForm()
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(
IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInCont
ext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(R
untimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fE
xecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMes
sage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
at ServiceClass.LoadForm()
at Client.Main()
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\M
icrosoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure lo
gging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fus
ion!EnableLog].