remoting/serialization problem
-
hey! i've a nice remoting/serialization problem: i call a method of my server object, which needs a font parameter. if i access this font parameter in my server method i get a remoting exception. the cause of this problem is clear (?): if i read a property value of this font object, the server tries to call the property accessor on client side... meanwhile i call my method without font parameter and with parameters like fontname, fontsize(...) instead... but that's not the smoothest way, i think! is there a way to use font parameters without exception? font implements iserialization - but why becomes it not serialized? thanks in advance
Yes, the
Font
is serializable, but what channel are you using for remoting? If you are hosting your remoting object in IIS, it can only use the HttpChannel. HTTP - by nature - is one way. The server can't initiate communications with the client. With you pass the name, size, etc., these are all value types (except for strings, which behave similarily) and are pass-by-value without using them as properties or theref
andout
keywords. Also, what exactly is the exception? The Type and message would help.Microsoft MVP, Visual C# My Articles
-
Yes, the
Font
is serializable, but what channel are you using for remoting? If you are hosting your remoting object in IIS, it can only use the HttpChannel. HTTP - by nature - is one way. The server can't initiate communications with the client. With you pass the name, size, etc., these are all value types (except for strings, which behave similarily) and are pass-by-value without using them as properties or theref
andout
keywords. Also, what exactly is the exception? The Type and message would help.Microsoft MVP, Visual C# My Articles
I'm using a TCP Channel. The Exception is something like that: "The Remotechannel has no Channelreceiver, it means that the Server has no registered Serverchannel or that the Application has no matching Clientchannel to communicate with the Server." The type of the exception is
System.Runtime.Remoting.RemotingException
-
I'm using a TCP Channel. The Exception is something like that: "The Remotechannel has no Channelreceiver, it means that the Server has no registered Serverchannel or that the Application has no matching Clientchannel to communicate with the Server." The type of the exception is
System.Runtime.Remoting.RemotingException
What type of client- or server-activated type are you using (and which one of those is it)?
Microsoft MVP, Visual C# My Articles
-
What type of client- or server-activated type are you using (and which one of those is it)?
Microsoft MVP, Visual C# My Articles
-
It's obvious the server is having trouble communicating with the client. What's not obvious is how you are registering the WKO on the server and connecting to it on the client. If you're using a config file to configure the remoting (both on the server and on the client, which in most cases is a better way so you don't have to recompile), could you post the relevent sections? Don't forget to escape your < and >, or check the "Do not treat <'s as HTML tags" below before posting.
Microsoft MVP, Visual C# My Articles
-
It's obvious the server is having trouble communicating with the client. What's not obvious is how you are registering the WKO on the server and connecting to it on the client. If you're using a config file to configure the remoting (both on the server and on the client, which in most cases is a better way so you don't have to recompile), could you post the relevent sections? Don't forget to escape your < and >, or check the "Do not treat <'s as HTML tags" below before posting.
Microsoft MVP, Visual C# My Articles
okay! i register my object in source code. here's an extract of the code to do this:
//client: public void ConnectToServer(Type ObjectType) { TCPChannel Channel=new TcpClientChannel("ClientChannel",null); ChannelServices.RegisterChannel(Channel); RemotingConfiguration.RegisterWellKnownClientType(ObjectType,"tcp://server:10000/server.rem"); } //server: public void PublishObject() { TCPChannel Channel=new TcpServerChannel("ServerChannel",10000); ChannelServices.RegisterChannel(Channel); ServerObject Obj=new ServerObject(); RemotingServices.Marshal(Obj,"server.rem",typeof(ServerObject)); }
-
It's obvious the server is having trouble communicating with the client. What's not obvious is how you are registering the WKO on the server and connecting to it on the client. If you're using a config file to configure the remoting (both on the server and on the client, which in most cases is a better way so you don't have to recompile), could you post the relevent sections? Don't forget to escape your < and >, or check the "Do not treat <'s as HTML tags" below before posting.
Microsoft MVP, Visual C# My Articles
-
okay! i register my object in source code. here's an extract of the code to do this:
//client: public void ConnectToServer(Type ObjectType) { TCPChannel Channel=new TcpClientChannel("ClientChannel",null); ChannelServices.RegisterChannel(Channel); RemotingConfiguration.RegisterWellKnownClientType(ObjectType,"tcp://server:10000/server.rem"); } //server: public void PublishObject() { TCPChannel Channel=new TcpServerChannel("ServerChannel",10000); ChannelServices.RegisterChannel(Channel); ServerObject Obj=new ServerObject(); RemotingServices.Marshal(Obj,"server.rem",typeof(ServerObject)); }
Actually, this looks like a server-activated type. Using
RemotingConfiguration.RegisterActivatedClientType
would create the client-activated type. I'm having a friend look at this thread, though. He's a little better with this type of Remoting stuff than I.Microsoft MVP, Visual C# My Articles
-
okay! i register my object in source code. here's an extract of the code to do this:
//client: public void ConnectToServer(Type ObjectType) { TCPChannel Channel=new TcpClientChannel("ClientChannel",null); ChannelServices.RegisterChannel(Channel); RemotingConfiguration.RegisterWellKnownClientType(ObjectType,"tcp://server:10000/server.rem"); } //server: public void PublishObject() { TCPChannel Channel=new TcpServerChannel("ServerChannel",10000); ChannelServices.RegisterChannel(Channel); ServerObject Obj=new ServerObject(); RemotingServices.Marshal(Obj,"server.rem",typeof(ServerObject)); }
One thing that worries me from inspecting this code snip is that you might be mixing your client and server types. You register
ObjectType
as your remoted object but then use another objectServerObject
on the server. The object being remoted must be the same or implement the same interface. This is important because even ifObjectType
is derived fromServerType
the Remoting Framework only has registered/recognizesObjectType
as remotable.ServerType
is just another type it will handle outside of the Remoting Framework. Both the client and server parts need to be dealing with the same object or deal with an interface or you get the wrong behavior. Next once you seem to be usingRemotingServices.Marshal
in the wrong context.Marshal
is used to transfer aMarshalByRefObject
across application domains which has little to do with actually "publishing" the service. What I recommend doing is using configuration files on both the client and the server and usingRemotingConfiguration.Configure
. The client config file from your code snip should look something like this:<configuration>
<system.runtime.remoting>
<application>
<client url="tcp://server:10000">
<wellknown
type = "ObjectType,ObjectAssembly"
url = "tcp://server:10000/server.rem" />
<!-- or atlernatively, the client activated version
<activated type="ObjectType,ObjectAssembly" />
-->
</client>
<channels>
<channel ref="tcp" port="10000" />
</channels>
</application>
</system.runtime.remoting>
</configuration>Your server config file should look something like this:
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode="SingleCall" type="ObjectType, ObjectAssembly" objectUri="server.rem" />
<!-- alternatively, the client activated version
<activated type="ObjectType, ObjectAssembly" />
-->
</service>
<channels>
<channel ref="tcp" port="10000" />
</channels>
</application>
</system.runtime.remoting>
</configuration>If you use config files you don't have to worry about setup or teardown of ch
-
One thing that worries me from inspecting this code snip is that you might be mixing your client and server types. You register
ObjectType
as your remoted object but then use another objectServerObject
on the server. The object being remoted must be the same or implement the same interface. This is important because even ifObjectType
is derived fromServerType
the Remoting Framework only has registered/recognizesObjectType
as remotable.ServerType
is just another type it will handle outside of the Remoting Framework. Both the client and server parts need to be dealing with the same object or deal with an interface or you get the wrong behavior. Next once you seem to be usingRemotingServices.Marshal
in the wrong context.Marshal
is used to transfer aMarshalByRefObject
across application domains which has little to do with actually "publishing" the service. What I recommend doing is using configuration files on both the client and the server and usingRemotingConfiguration.Configure
. The client config file from your code snip should look something like this:<configuration>
<system.runtime.remoting>
<application>
<client url="tcp://server:10000">
<wellknown
type = "ObjectType,ObjectAssembly"
url = "tcp://server:10000/server.rem" />
<!-- or atlernatively, the client activated version
<activated type="ObjectType,ObjectAssembly" />
-->
</client>
<channels>
<channel ref="tcp" port="10000" />
</channels>
</application>
</system.runtime.remoting>
</configuration>Your server config file should look something like this:
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode="SingleCall" type="ObjectType, ObjectAssembly" objectUri="server.rem" />
<!-- alternatively, the client activated version
<activated type="ObjectType, ObjectAssembly" />
-->
</service>
<channels>
<channel ref="tcp" port="10000" />
</channels>
</application>
</system.runtime.remoting>
</configuration>If you use config files you don't have to worry about setup or teardown of ch