[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

Windows Service using remoting

Chuck Douglas

7/13/2004 4:07:00 PM

I am having a problem with using remoting and I am hoping someone might
have run into this problem before.

I have developed a Windows service, which has the following OnStart method
override.

protected override void OnStart(string[] args)
{
TcpChannel channel = new TcpChannel(8085);
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownServiceType(
Type.GetType("ObjectModel.Engine,ObjectModel"),
"TestEngine", WellKnownObjectMode.Singleton);
}

As you can see from the code above, I have a server object called
"ObjectModel.Engine". It is derived from MarshalByRefObject. This is built
into a DLL called ObjectModel.dll. It is one simple class which a very
simple interface, which I want to call remotely.

I also have a client application, which has the following code. It uses
Activator.GetObject to get the proxy and calls the interface of the
ObjectModel.Engine object.

[STAThread]
static void Main(string[] args)
{
TcpChannel channel = new TcpChannel();
ChannelServices.RegisterChannel(channel);
ObjectModel.Engine obj = (ObjectModel.Engine) Activator.GetObject(
typeof(ObjectModel.Engine),
"tcp://chdougla:8085/TestEngine");

string prefix = args[0];
if (obj != null)
{
obj.Add(prefix + "fred");
System.Console.WriteLine(obj.ToStr());
}
else
{
System.Console.WriteLine("Could not locate server - ");
}
}

I can successfully run the client and server on the same machine. I have
debugged into the windows service process id to verify that I was really
executing the remote code. However, when I try to put the client exe on
another machine then I get the following error. It seems like a
security/permissions problem, but I am not sure.

Also, here are some followup questions. When I run the client exe, why
is my ObjectModel.dll automatically downloaded from the server? Is this
expected, as part of remoting? Is this a proxy dll or the real dll? When I
physically copy the ObjectModel.dll to the same directory as the client exe,
on another machine, things seem to work fine. I wouldn't expect that I
would have to copy the server dll on every client machine though?

Any help anyone can provide would be very much appreciated.

Thanks


3 Answers

Chuck Douglas

7/13/2004 4:10:00 PM

0

Ooops. Here is the error that I am getting.

Unhandled Exception: System.IO.FileNotFoundException: File or assembly name
Obje
ctModel, or one of its dependencies, was not found.
File name: "ObjectModel"
at Client1.Client1.Main(String[] args)

=== Pre-bind state information ===
LOG: DisplayName = ObjectModel, Version=1.0.1654.20166, Culture=neutral,
PublicK
eyToken=5fa67588008b079e
(Fully-specified)
LOG: Appbase = F:\downloadLOG: Initial PrivatePath = NULL
Calling assembly : Client1, Version=1.0.1654.20415, Culture=neutral,
PublicKeyTo
ken=null.
===

LOG: Publisher policy file is not found.
LOG: Host configuration file not found.
LOG: Using machine configuration file from
F:\WINDOWS\Microsoft.NET\Framework\v1
..1.4322\config\machine.config.
LOG: Post-policy reference: ObjectModel, Version=1.0.1654.20166,
Culture=neutral
, PublicKeyToken=5fa67588008b079e
LOG: Attempting download of new URL file:///F:/download/ObjectModel.DLL.
LOG: Attempting download of new URL
file:///F:/download/ObjectModel/ObjectModel.
DLL.
LOG: Attempting download of new URL file:///F:/download/ObjectModel.EXE.
LOG: Attempting download of new URL
file:///F:/download/ObjectModel/ObjectModel.
EXE.

"Chuck Douglas" <cdouglas@mapinfo.com> wrote in message
news:%23GwspNPaEHA.808@tk2msftngp13.phx.gbl...
> I am having a problem with using remoting and I am hoping someone might
> have run into this problem before.
>
> I have developed a Windows service, which has the following OnStart
method
> override.
>
> protected override void OnStart(string[] args)
> {
> TcpChannel channel = new TcpChannel(8085);
> ChannelServices.RegisterChannel(channel);
> RemotingConfiguration.RegisterWellKnownServiceType(
> Type.GetType("ObjectModel.Engine,ObjectModel"),
> "TestEngine", WellKnownObjectMode.Singleton);
> }
>
> As you can see from the code above, I have a server object called
> "ObjectModel.Engine". It is derived from MarshalByRefObject. This is
built
> into a DLL called ObjectModel.dll. It is one simple class which a very
> simple interface, which I want to call remotely.
>
> I also have a client application, which has the following code. It
uses
> Activator.GetObject to get the proxy and calls the interface of the
> ObjectModel.Engine object.
>
> [STAThread]
> static void Main(string[] args)
> {
> TcpChannel channel = new TcpChannel();
> ChannelServices.RegisterChannel(channel);
> ObjectModel.Engine obj = (ObjectModel.Engine) Activator.GetObject(
> typeof(ObjectModel.Engine),
> "tcp://chdougla:8085/TestEngine");
>
> string prefix = args[0];
> if (obj != null)
> {
> obj.Add(prefix + "fred");
> System.Console.WriteLine(obj.ToStr());
> }
> else
> {
> System.Console.WriteLine("Could not locate server - ");
> }
> }
>
> I can successfully run the client and server on the same machine. I
have
> debugged into the windows service process id to verify that I was really
> executing the remote code. However, when I try to put the client exe on
> another machine then I get the following error. It seems like a
> security/permissions problem, but I am not sure.
>
> Also, here are some followup questions. When I run the client exe, why
> is my ObjectModel.dll automatically downloaded from the server? Is this
> expected, as part of remoting? Is this a proxy dll or the real dll? When
I
> physically copy the ObjectModel.dll to the same directory as the client
exe,
> on another machine, things seem to work fine. I wouldn''t expect that I
> would have to copy the server dll on every client machine though?
>
> Any help anyone can provide would be very much appreciated.
>
> Thanks
>
>


Sunny

7/13/2004 6:29:00 PM

0

Both the server and the client have to have access to the assembly in
which the object is declared. As it is not good to have your object code
distributed with the client, you can use:

1. soapsuds.exe utility to extract the meta-data info, and distribute
only this metadata. There are some problems with the this utility, and
some limitation.

thats why I usually recommend:
2. Interfaces or abstract class libraries. Allen Andersons article about
abstract class approach is very good. You can use the same with
interfaces as well:

http://www.glacialcomponents.com/ArticleDe...
articleID=RemoteObject

Sunny




In article <uYgrWPPaEHA.2296@TK2MSFTNGP10.phx.gbl>, cdouglas@mapinfo.com
says...
> Ooops. Here is the error that I am getting.
>
> Unhandled Exception: System.IO.FileNotFoundException: File or assembly name
> Obje
> ctModel, or one of its dependencies, was not found.
> File name: "ObjectModel"
> at Client1.Client1.Main(String[] args)
>
> === Pre-bind state information ===
> LOG: DisplayName = ObjectModel, Version=1.0.1654.20166, Culture=neutral,
> PublicK
> eyToken=5fa67588008b079e
> (Fully-specified)
> LOG: Appbase = F:\download> LOG: Initial PrivatePath = NULL
> Calling assembly : Client1, Version=1.0.1654.20415, Culture=neutral,
> PublicKeyTo
> ken=null.
> ===
>
> LOG: Publisher policy file is not found.
> LOG: Host configuration file not found.
> LOG: Using machine configuration file from
> F:\WINDOWS\Microsoft.NET\Framework\v1
> .1.4322\config\machine.config.
> LOG: Post-policy reference: ObjectModel, Version=1.0.1654.20166,
> Culture=neutral
> , PublicKeyToken=5fa67588008b079e
> LOG: Attempting download of new URL file:///F:/download/ObjectModel.DLL.
> LOG: Attempting download of new URL
> file:///F:/download/ObjectModel/ObjectModel.
> DLL.
> LOG: Attempting download of new URL file:///F:/download/ObjectModel.EXE.
> LOG: Attempting download of new URL
> file:///F:/download/ObjectModel/ObjectModel.
> EXE.
>
> "Chuck Douglas" <cdouglas@mapinfo.com> wrote in message
> news:%23GwspNPaEHA.808@tk2msftngp13.phx.gbl...
> > I am having a problem with using remoting and I am hoping someone might
> > have run into this problem before.
> >
> > I have developed a Windows service, which has the following OnStart
> method
> > override.
> >
> > protected override void OnStart(string[] args)
> > {
> > TcpChannel channel = new TcpChannel(8085);
> > ChannelServices.RegisterChannel(channel);
> > RemotingConfiguration.RegisterWellKnownServiceType(
> > Type.GetType("ObjectModel.Engine,ObjectModel"),
> > "TestEngine", WellKnownObjectMode.Singleton);
> > }
> >
> > As you can see from the code above, I have a server object called
> > "ObjectModel.Engine". It is derived from MarshalByRefObject. This is
> built
> > into a DLL called ObjectModel.dll. It is one simple class which a very
> > simple interface, which I want to call remotely.
> >
> > I also have a client application, which has the following code. It
> uses
> > Activator.GetObject to get the proxy and calls the interface of the
> > ObjectModel.Engine object.
> >
> > [STAThread]
> > static void Main(string[] args)
> > {
> > TcpChannel channel = new TcpChannel();
> > ChannelServices.RegisterChannel(channel);
> > ObjectModel.Engine obj = (ObjectModel.Engine) Activator.GetObject(
> > typeof(ObjectModel.Engine),
> > "tcp://chdougla:8085/TestEngine");
> >
> > string prefix = args[0];
> > if (obj != null)
> > {
> > obj.Add(prefix + "fred");
> > System.Console.WriteLine(obj.ToStr());
> > }
> > else
> > {
> > System.Console.WriteLine("Could not locate server - ");
> > }
> > }
> >
> > I can successfully run the client and server on the same machine. I
> have
> > debugged into the windows service process id to verify that I was really
> > executing the remote code. However, when I try to put the client exe on
> > another machine then I get the following error. It seems like a
> > security/permissions problem, but I am not sure.
> >
> > Also, here are some followup questions. When I run the client exe, why
> > is my ObjectModel.dll automatically downloaded from the server? Is this
> > expected, as part of remoting? Is this a proxy dll or the real dll? When
> I
> > physically copy the ObjectModel.dll to the same directory as the client
> exe,
> > on another machine, things seem to work fine. I wouldn''t expect that I
> > would have to copy the server dll on every client machine though?
> >
> > Any help anyone can provide would be very much appreciated.
> >
> > Thanks
> >
> >
>
>
>

Chuck Douglas

7/13/2004 7:11:00 PM

0

Sunny,

Thanks for the reply. That is exactly what I was looking for. I will
use the interface or abstract base class approach.

Thanks again
Chuck

"Sunny" <sunny@newsgroups.nospam> wrote in message
news:u2hQ9cQaEHA.2408@tk2msftngp13.phx.gbl...
> Both the server and the client have to have access to the assembly in
> which the object is declared. As it is not good to have your object code
> distributed with the client, you can use:
>
> 1. soapsuds.exe utility to extract the meta-data info, and distribute
> only this metadata. There are some problems with the this utility, and
> some limitation.
>
> thats why I usually recommend:
> 2. Interfaces or abstract class libraries. Allen Andersons article about
> abstract class approach is very good. You can use the same with
> interfaces as well:
>
> http://www.glacialcomponents.com/ArticleDe...
> articleID=RemoteObject
>
> Sunny
>
>
>
>
> In article <uYgrWPPaEHA.2296@TK2MSFTNGP10.phx.gbl>, cdouglas@mapinfo.com
> says...
> > Ooops. Here is the error that I am getting.
> >
> > Unhandled Exception: System.IO.FileNotFoundException: File or assembly
name
> > Obje
> > ctModel, or one of its dependencies, was not found.
> > File name: "ObjectModel"
> > at Client1.Client1.Main(String[] args)
> >
> > === Pre-bind state information ===
> > LOG: DisplayName = ObjectModel, Version=1.0.1654.20166, Culture=neutral,
> > PublicK
> > eyToken=5fa67588008b079e
> > (Fully-specified)
> > LOG: Appbase = F:\download> > LOG: Initial PrivatePath = NULL
> > Calling assembly : Client1, Version=1.0.1654.20415, Culture=neutral,
> > PublicKeyTo
> > ken=null.
> > ===
> >
> > LOG: Publisher policy file is not found.
> > LOG: Host configuration file not found.
> > LOG: Using machine configuration file from
> > F:\WINDOWS\Microsoft.NET\Framework\v1
> > .1.4322\config\machine.config.
> > LOG: Post-policy reference: ObjectModel, Version=1.0.1654.20166,
> > Culture=neutral
> > , PublicKeyToken=5fa67588008b079e
> > LOG: Attempting download of new URL file:///F:/download/ObjectModel.DLL.
> > LOG: Attempting download of new URL
> > file:///F:/download/ObjectModel/ObjectModel.
> > DLL.
> > LOG: Attempting download of new URL file:///F:/download/ObjectModel.EXE.
> > LOG: Attempting download of new URL
> > file:///F:/download/ObjectModel/ObjectModel.
> > EXE.
> >
> > "Chuck Douglas" <cdouglas@mapinfo.com> wrote in message
> > news:%23GwspNPaEHA.808@tk2msftngp13.phx.gbl...
> > > I am having a problem with using remoting and I am hoping someone
might
> > > have run into this problem before.
> > >
> > > I have developed a Windows service, which has the following OnStart
> > method
> > > override.
> > >
> > > protected override void OnStart(string[] args)
> > > {
> > > TcpChannel channel = new TcpChannel(8085);
> > > ChannelServices.RegisterChannel(channel);
> > > RemotingConfiguration.RegisterWellKnownServiceType(
> > > Type.GetType("ObjectModel.Engine,ObjectModel"),
> > > "TestEngine", WellKnownObjectMode.Singleton);
> > > }
> > >
> > > As you can see from the code above, I have a server object called
> > > "ObjectModel.Engine". It is derived from MarshalByRefObject. This is
> > built
> > > into a DLL called ObjectModel.dll. It is one simple class which a
very
> > > simple interface, which I want to call remotely.
> > >
> > > I also have a client application, which has the following code. It
> > uses
> > > Activator.GetObject to get the proxy and calls the interface of the
> > > ObjectModel.Engine object.
> > >
> > > [STAThread]
> > > static void Main(string[] args)
> > > {
> > > TcpChannel channel = new TcpChannel();
> > > ChannelServices.RegisterChannel(channel);
> > > ObjectModel.Engine obj = (ObjectModel.Engine) Activator.GetObject(
> > > typeof(ObjectModel.Engine),
> > > "tcp://chdougla:8085/TestEngine");
> > >
> > > string prefix = args[0];
> > > if (obj != null)
> > > {
> > > obj.Add(prefix + "fred");
> > > System.Console.WriteLine(obj.ToStr());
> > > }
> > > else
> > > {
> > > System.Console.WriteLine("Could not locate server - ");
> > > }
> > > }
> > >
> > > I can successfully run the client and server on the same machine.
I
> > have
> > > debugged into the windows service process id to verify that I was
really
> > > executing the remote code. However, when I try to put the client exe
on
> > > another machine then I get the following error. It seems like a
> > > security/permissions problem, but I am not sure.
> > >
> > > Also, here are some followup questions. When I run the client exe,
why
> > > is my ObjectModel.dll automatically downloaded from the server? Is
this
> > > expected, as part of remoting? Is this a proxy dll or the real dll?
When
> > I
> > > physically copy the ObjectModel.dll to the same directory as the
client
> > exe,
> > > on another machine, things seem to work fine. I wouldn''t expect that
I
> > > would have to copy the server dll on every client machine though?
> > >
> > > Any help anyone can provide would be very much appreciated.
> > >
> > > Thanks
> > >
> > >
> >
> >
> >