Remoting, how to create the remote server

C

Claus Frederiksen

Hi All

Maybe I am missing something but can anyone explain how i connect to
the server using af setting file?

This is my code and setting file. The 'else' part connects to the
server, but how do I connect using a setting file?

The Code:

public Observer()
{
string dllfile =
System.Reflection.Assembly.GetExecutingAssembly().Location;
string path =
dllfile.Substring(0,dllfile.LastIndexOf("\\"));
string settingFile = string.Format("{0}\\{1}", path,
"client.config");

if (System.IO.File.Exists(settingFile))
{

System.Runtime.Remoting.RemotingConfiguration.Configure(settingFile,
false);
//How do i get the remoting object on the server,
using my settingFile
}
else
{
//select channel to communicate with server
BinaryClientFormatterSinkProvider clientProvider = new
BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider serverProvider = new
BinaryServerFormatterSinkProvider();

serverProvider.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
System.Collections.IDictionary props = new
System.Collections.Hashtable();
props["port"] = 0;
props["typeFilterLevel"] =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

TcpChannel chan = new TcpChannel(props,
clientProvider, serverProvider);
ChannelServices.RegisterChannel(chan, false);
remObject =
(MCmessage)Activator.GetObject(typeof(MCmessage),
"tcp://localhost:9000/AppMessages.rem"); //URI skal være ens i server
og klient og kan tilsyneladende ikke sættes i config filen, selvom
den skal stå der
}
if (remObject == null)
Console.WriteLine("cannot locate server");
}
}

Xml file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.runtime.remoting>
<application>
<client>
<wellknown
type="MCmessage, MessageCommunication"
url="tcp://localhost:9000/AppMessages.rem"
/>
</client>
</application>
</system.runtime.remoting>
</configuration>


Regards Claus
 
A

Arne Vajhøj

Claus said:
Hi All

Maybe I am missing something but can anyone explain how i connect to
the server using af setting file?

This is my code and setting file. The 'else' part connects to the
server, but how do I connect using a setting file?

The Code:

public Observer()
{
string dllfile =
System.Reflection.Assembly.GetExecutingAssembly().Location;
string path =
dllfile.Substring(0,dllfile.LastIndexOf("\\"));
string settingFile = string.Format("{0}\\{1}", path,
"client.config");

if (System.IO.File.Exists(settingFile))
{

System.Runtime.Remoting.RemotingConfiguration.Configure(settingFile,
false);
//How do i get the remoting object on the server,
using my settingFile
}
else
{
//select channel to communicate with server
BinaryClientFormatterSinkProvider clientProvider = new
BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider serverProvider = new
BinaryServerFormatterSinkProvider();

serverProvider.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
System.Collections.IDictionary props = new
System.Collections.Hashtable();
props["port"] = 0;
props["typeFilterLevel"] =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

TcpChannel chan = new TcpChannel(props,
clientProvider, serverProvider);
ChannelServices.RegisterChannel(chan, false);
remObject =
(MCmessage)Activator.GetObject(typeof(MCmessage),
"tcp://localhost:9000/AppMessages.rem"); //URI skal være ens i server
og klient og kan tilsyneladende ikke sættes i config filen, selvom
den skal stå der
}
if (remObject == null)
Console.WriteLine("cannot locate server");
}
}

Xml file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.runtime.remoting>
<application>
<client>
<wellknown
type="MCmessage, MessageCommunication"
url="tcp://localhost:9000/AppMessages.rem"
/>
</client>
</application>
</system.runtime.remoting>
</configuration>

I have not digested all your code, but can't you just use standard
app config and standard .NET classes to use it?

RemotingConfiguration.Configure

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top