473,383 Members | 1,855 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Remoting question

Hi,

I'm new to .NET remoting and there's something I'm having real trouble with.
Basically, I'd like to create a component that can act as a server and as a
client (can send messages and receive them in asynchronous mode).

Here's the situation just so you guys understand why I'm doing this (and
maybe so that you can provide me with other options):

I have an application that needs to save data to a remote database. The
DBAs don't allow direct modifications or insertions into the database for
security and other reasons. So, they built what we call here an INSERTION
SERVICE (IS). The application that wants to save to the db has to create an
XML file with the details of the changes and drop it on an FTP site for
processing. Problem is that the files can be rejected for many reasons so we
would like to inform the user whether his/her changes have been saved or not.
Since this is a very busy database, the changes are not necessarily done
immediately, the files are put in a priority queue.

So basically, once the changes have been made or not, we need to inform the
user in the App. We thought about building some kind of proxy that resides
between the application and the IS. The application would register itself to
the proxy everytime it sends a new file to the IS. Once the file has been
processed, the IS could send a message to the proxy that would dispatch it to
the App. So, the App would need to act as a client for the original
registration to the proxy and as a server for the reception of the final
message (vice-versa for the proxy).

I tried to create an Interface to derive the client with and then, when a
call is made by the client to the proxy, supply a link to themself (the
client) with the call. Hence, I could then call a procedure on that object
once the work is done.

Here's (snippets of) the code I have written up until now:
<THIS IS THE SHARED OBJECT CODE>
public interface IClient
{
void WorkCompleted(string msg);
}

public class RemoteMessage : MarshalByRefObject
{
public RemoteMessage()
{
ClientQueue = new ArrayList();
}
public void SetClient(string xmlFileName, IClient client)
{
//ClientInfo is a class that stores info on the client and
//a reference to the client (passed with the Interface ref)
ClientQueue.Add(new ClientInfo(xmlFileName, client));
}

public void SetMessage(string xmlFileName, string msg)
{
//Find the corresponding client according to its XML file (unique)
//and return a message through its client interface (asynchonous).
//Finally delete the entry for this client in the collection.
int i;

for (i=ClientQueue.Count-1; i>0; i--)
if (ClientQueue[i].ToString().Equals(xmlFileName))
{
ClientInfo obj = (ClientInfo) ClientQueue[i];
obj.GetClient.WorkCompleted(msg);
ClientQueue.RemoveAt(i);
//Could stop but for debugging purposes, we will continue in case object
is there more than once
}
}

private System.Collections.ArrayList ClientQueue;
}

<THIS IS THE CLIENT CODE>
class Client : IClient
{
RemoteMessage server;
HttpChannel channel;

public Client()
{
Console.WriteLine("***** Client started *****");
Console.WriteLine("Hit ENTER to end.");
}

public void Register()
{
channel = new HttpChannel();
ChannelServices.RegisterChannel(channel);

object remoteObj = Activator.GetObject(
typeof(SI_Remoting.RemoteMessage),
"http://localhost:32469/RemoteServer.soap");

server = (RemoteMessage) remoteObj;

}

public void RegisterNewMsg(string xml)
{
server.SetClient(xml, this);
}

//this will be called by the SI
public void UnregisterMsg(string xml, string msg)
{
server.SetMessage(xml, msg);
}
public void WorkCompleted(string msg)
{
//Return the message sent to DVS.
Console.WriteLine("Received message: {0}", msg);
}

[STAThread]
static void Main(string[] args)
{
Client client = new Client();

client.Register();
client.RegisterNewMsg("xml1");
//client.UnregisterMsg("xml1", "xml has been processed.");

Console.ReadLine();
}
}

I'm having lots of issues with the components I need to serialize and all
the configuration that should be wrapped in there too in order for this to
work. Actually, this code compiles correctly but at run time I get the
following error when I start the client:

Unhandled Exception: System.Runtime.Serialization.SerializationExceptio n:
The type SI_Client.Client in Assembly SI_Client, Version=1.0.1741.22769,
Culture=neutral, PublicKeyToken=null is not marked as serializable.

I don't know what to do next (because I don't want to start putting
[Serializable] tags everywhere or other stuff until it works, I want to
understand what I do).

Thanks a lot in advance for all your help,

Skip.
Nov 16 '05 #1
3 3017
Two things I can see are:

You need to pass 0 to the constructor of the channel in the client - otherwise it won't listen on a port and so won't be able to receive callbacks

The Client needs to derive from MarshalByRefObject so that the server receives a proxy to it (and so callbacks will be remoted back to the client)

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<AE**********************************@microsoft.co m>

Hi,

I'm new to .NET remoting and there's something I'm having real trouble with.
Basically, I'd like to create a component that can act as a server and as a
client (can send messages and receive them in asynchronous mode).

<THIS IS THE CLIENT CODE>
class Client : IClient
{
RemoteMessage server;
HttpChannel channel;

public Client()
{
Console.WriteLine("***** Client started *****");
Console.WriteLine("Hit ENTER to end.");
}

public void Register()
{
channel = new HttpChannel();
ChannelServices.RegisterChannel(channel);

object remoteObj = Activator.GetObject(
typeof(SI_Remoting.RemoteMessage),
"http://localhost:32469/RemoteServer.soap");

server = (RemoteMessage) remoteObj;

}

public void RegisterNewMsg(string xml)
{
server.SetClient(xml, this);
}

//this will be called by the SI
public void UnregisterMsg(string xml, string msg)
{
server.SetMessage(xml, msg);
}
public void WorkCompleted(string msg)
{
//Return the message sent to DVS.
Console.WriteLine("Received message: {0}", msg);
}

[STAThread]
static void Main(string[] args)
{
Client client = new Client();

client.Register();
client.RegisterNewMsg("xml1");
//client.UnregisterMsg("xml1", "xml has been processed.");

Console.ReadLine();
}
}

I'm having lots of issues with the components I need to serialize and all
the configuration that should be wrapped in there too in order for this to
work. Actually, this code compiles correctly but at run time I get the
following error when I start the client:

Unhandled Exception: System.Runtime.Serialization.SerializationExceptio n:
The type SI_Client.Client in Assembly SI_Client, Version=1.0.1741.22769,
Culture=neutral, PublicKeyToken=null is not marked as serializable.

I don't know what to do next (because I don't want to start putting
[Serializable] tags everywhere or other stuff until it works, I want to
understand what I do).

Thanks a lot in advance for all your help,

Skip.

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004

[microsoft.public.dotnet.languages.csharp]
Nov 16 '05 #2
Thanks Richard,

I did what you proposed but now, I get the following exception (which really
doesn't say much):

Unhandled Exception: System.Runtime.Serialization.SerializationExceptio n:
Because of security restrictions, the type System.Runtime.Remoting.ObjRef ca
nnot be accessed. ---> System.Security.SecurityException: Request failed.
at
System.Security.SecurityRuntime.FrameDescSetHelper (FrameSecurityDescriptor
secDesc, PermissionSet demandSet, PermissionSet& alteredDemandSet)
at
System.Runtime.Serialization.FormatterServices.nat iveGetSafeUninitializedObject(RuntimeType type)
at
System.Runtime.Serialization.FormatterServices.Get SafeUninitializedObject(Type type)
--- End of inner exception stack trace ---

Server stack trace:
at
System.Runtime.Serialization.FormatterServices.Get SafeUninitializedObject(Type type)
at
System.Runtime.Serialization.Formatters.Soap.Objec tReader.ParseObject(ParseRecord pr)
at
System.Runtime.Serialization.Formatters.Soap.Objec tReader.Parse(ParseRecord
pr)
at System.Runtime.Serialization.Formatters.Soap.SoapH andler.StartChildren()
at System.Runtime.Serialization.Formatters.Soap.SoapP arser.ParseXml()
at System.Runtime.Serialization.Formatters.Soap.SoapP arser.Run()
at
System.Runtime.Serialization.Formatters.Soap.Objec tReader.Deserialize(HeaderHandler handler, ISerParser serParser)
at
System.Runtime.Serialization.Formatters.Soap.SoapF ormatter.Deserialize(Stream
serializationStream, HeaderHandler handler)
at
System.Runtime.Remoting.Channels.CoreChannel.Deser ializeSoapRequestMessage(Stream inputStream, Header[] h, Boolean bStrictBinding, TypeFilterLev
el securityLevel)
at
System.Runtime.Remoting.Channels.SoapServerFormatt erSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeader
s requestHeaders, Stream requestStream, IMessage& responseMsg,
ITransportHeaders& responseHeaders, Stream& responseStream)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleRe turnMessage(IMessage
reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateI nvoke(MessageData&
msgData, Int32 type)
at SI_Remoting.RemoteMessage.SetClient(String xmlFileName, IClient
client) in
c:\_dev\dotnet\si_proxy\si_remoting\si_remoting\re motemessage.cs:line
33
at SI_Client.Client.RegisterNewMsg(String xml) in
c:\_dev\dotnet\si_proxy\si_client\si_client\client .cs:line 35
at SI_Client.Client.Main(String[] args) in
c:\_dev\dotnet\si_proxy\si_client\si_client\client .cs:line 57

Do I need to set something for security purposes?

Thanks again,

SC
Nov 16 '05 #3
OK, this was introduced in version 1.1 of the framework. On the server side you need to open up the TypeFilter to full. I can remember how to do it with config files (as I always use them for remoting)

<formatter ref="binary" typeFilterLevel="Full"/>

But with code I can't remember off the top of my head but this link shows you how

http://blogs.msdn.com/sanpil/archive.../23/78754.aspx

The basis of this is that they decided to prevent non-primitive objects being sent across the wire as it essentially injected code into the server if the type had a static constructor (the code wouol run pure because of the type's presence not because anything was called) and this was seen as a potential security issue so it is turned off by default.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<01**********************************@microsoft.co m>

Thanks Richard,

I did what you proposed but now, I get the following exception (which really
doesn't say much):

Unhandled Exception: System.Runtime.Serialization.SerializationExceptio n:
Because of security restrictions, the type System.Runtime.Remoting.ObjRef ca
nnot be accessed. ---> System.Security.SecurityException: Request failed.
at
System.Security.SecurityRuntime.FrameDescSetHelper (FrameSecurityDescriptor
secDesc, PermissionSet demandSet, PermissionSet& alteredDemandSet)
at
System.Runtime.Serialization.FormatterServices.nat iveGetSafeUninitializedObject(RuntimeType type)
at
System.Runtime.Serialization.FormatterServices.Get SafeUninitializedObject(Type type)
--- End of inner exception stack trace ---
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sean Newton | last post by:
I am absolutely bewildered by now by the Microsoft.Samples SSPI and Security assemblies. I've been trying to set these up in a very straightforward harness in the way that I'd like to be able to...
0
by: Dennis Owens | last post by:
Read below for previous conversation. We are developing an application that will some day run on anything from a computer down to a PDA (this is were the Lightweight comes in). The messaging...
15
by: anders | last post by:
Hi! I have a config file that looks like this: <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.runtime.remoting> <application> <service> <wellknown mode="SingleCall"...
5
by: DraguVaso | last post by:
Hi, I need to write a VB.NET-application (Windows Forms) that may have a part of it (re-)implemented as a Webpage for the customers. I think it can be usefull to create a business Layer with...
10
by: Michael Culley | last post by:
In vb6 it was possible to create an exe as an activeX exe and communicate between 2 apps. Now we have remoting which requires opening a tcp port to listen on, which seems kinda crappy cause another...
6
by: Uttam | last post by:
Hello, We are at a very crucial decision making stage to select between .Net and Java. Our requirement is to download a class at runtime on the client computer and execute it using remoting or...
3
by: Lucas Tam | last post by:
Does anyone have a good articles that describes the pros and cons of Web Services vs. Remoting Hosted in IIS? Is there a reason to use either or? With Remoting Hosting in IIS, is it possible...
9
by: Nak | last post by:
Hi there, I have been messing around with remoting in an attempt to create a "shared application" as mentioned in another thread by that name. I have created a singleton object just like the...
2
by: Ryan | last post by:
My apologies if this is not the forum to post questions regarding .NET Remoting, but I figured WebServices would be the most appropriate forum of the bunch. We're currently completely re-arching...
2
by: erbilkonuk | last post by:
Hi, I am very new to .NET Remoting and I try to run a simple program to subscribe to an event raised by Remoting Class. The Remoting Server initiates an instance of Remoting Class as Singleton /...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.