config file vs code



I am trying to remote some objects using .net remoting. I
programmatically create the remote object on the client side with the
following code

bool found = false;
for (int i = 0; i <
ChannelServices.RegisteredChannels.Length; i++)
{
if
(ChannelServices.RegisteredChannels[i].ChannelName.Equals("tcp"))
{
found = true;
break;
}
}
if (!found)
{
BinaryClientFormatterSinkProvider clientProvider =
new BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider serverProvider =
new BinaryServerFormatterSinkProvider();
serverProvider.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

IDictionary props = new Hashtable();
props["port"] = 0;
props["typeFilterLevel"] =
TypeFilterLevel.Full;
TcpChannel chan = new TcpChannel(props,
clientProvider, serverProvider);
ChannelServices.RegisterChannel(chan, false);
}
System.Text.StringBuilder sb = new
System.Text.StringBuilder();

sb.AppendFormat("tcp://{0}:{1}/{2}/{3}",
remotingConfig.RemotingServerName, remotingConfig.RemotingPortNumber,
REMOTING_SERVICE_NAME, controllerType.Name);

Type typeofRI = controllerType;

object controllerExecRemoteObject =
Activator.GetObject(typeofRI,
sb.ToString());


controllerExecRemoteObject.GetType().GetMethod("Ping").Invoke(controllerExecRemoteObject,
null);

return controllerExecRemoteObject;

This works but randomly I get a socket exception "Exception has been
thrown by the target of an invocation." InnerException Message: No
connection could be made because the target machine actively refused
it

What is strange is when I run it using a config file to controll the
remoting like so, it works? Is there something missing in my code
above that the config file does that my code doesn't?

Here is the config:
<configuration>
<system.runtime.remoting>
<application name="et.Exec.ExecBase">
<client>
<wellknown type="et.Exec.Controllers.AlertControllerExec,
et.Exec.Controllers"
url="tcp://localhost:8057/etRemotingService/AlertControllerExec" /

</client>
<channels>
<channel ref="tcp" port="0">
<clientProviders>
<formatter ref="binary" />
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>

.



Relevant Pages

  • RE: .NET Remoting problem - exception "Object Reference not set to ins
    ... client or server side .config files). ... and in the client side access the object through this ip address. ... Please compare the same with your config file. ... and implementing an object from the General namespace. ...
    (microsoft.public.dotnet.framework)
  • Re: remoting options
    ... I also don't know if you can use a configuration file on the client side for a remote object hosted in IIS: although I don't see why not. ... If you were to do this, that config file would *not* be web.config. ... You'll also need a reference to your proxy|interface|abstract base class in your client project references. ... If none of the above makes sense, my advice is to try to create a simple console application client with just enough code in it to prove that it's getting a constructive response from the remote object. ...
    (microsoft.public.dotnet.distributed_apps)
  • Re: advice on anti-spam tools
    ... regular mail filter installs or not, ... I didn't have any problems reading the config file myself. ... client to wait between the first attempt and the time the message ... Gary Kline kline@xxxxxxxxxxx www.thought.org Public Service Unix ...
    (freebsd-questions)
  • Re: cannot call non-public or static methods remotely
    ... > When the client starts and the user wants to write to database or files to ... > he can do that only when a service is running on the server with a ... > Now I have a config file when I try to connect it gives me this error. ... > Public Function GetSetting(ByVal Key As String) As String ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: find process by processname
    ... I'm not aware of another way to determine a process (that's not saying there ... you may be able to use a config file, however, then you are still having to ... Smart Client DevCenter - http://msdn.microsoft.com/smartclient/ ...
    (microsoft.public.dotnet.framework.windowsforms)