473,594 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(s tring msg);
}

public class RemoteMessage : MarshalByRefObj ect
{
public RemoteMessage()
{
ClientQueue = new ArrayList();
}
public void SetClient(strin g 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(xmlF ileName, client));
}

public void SetMessage(stri ng 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().Equ als(xmlFileName ))
{
ClientInfo obj = (ClientInfo) ClientQueue[i];
obj.GetClient.W orkCompleted(ms g);
ClientQueue.Rem oveAt(i);
//Could stop but for debugging purposes, we will continue in case object
is there more than once
}
}

private System.Collecti ons.ArrayList ClientQueue;
}

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

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

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

object remoteObj = Activator.GetOb ject(
typeof(SI_Remot ing.RemoteMessa ge),
"http://localhost:32469/RemoteServer.so ap");

server = (RemoteMessage) remoteObj;

}

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

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

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

client.Register ();
client.Register NewMsg("xml1");
//client.Unregist erMsg("xml1", "xml has been processed.");

Console.ReadLin e();
}
}

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.S erializationExc eption:
The type SI_Client.Clien t in Assembly SI_Client, Version=1.0.174 1.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 3055
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 MarshalByRefObj ect 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.publi c.dotnet.langua ges.csharp/<AE************ *************** *******@microso ft.com>

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.WriteLi ne("***** Client started *****");
Console.WriteLi ne("Hit ENTER to end.");
}

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

object remoteObj = Activator.GetOb ject(
typeof(SI_Remot ing.RemoteMessa ge),
"http://localhost:32469/RemoteServer.so ap");

server = (RemoteMessage) remoteObj;

}

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

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

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

client.Register ();
client.Register NewMsg("xml1");
//client.Unregist erMsg("xml1", "xml has been processed.");

Console.ReadLin e();
}
}

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.S erializationExc eption:
The type SI_Client.Clien t in Assembly SI_Client, Version=1.0.174 1.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.publi c.dotnet.langua ges.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.S erializationExc eption:
Because of security restrictions, the type System.Runtime. Remoting.ObjRef ca
nnot be accessed. ---> System.Security .SecurityExcept ion: Request failed.
at
System.Security .SecurityRuntim e.FrameDescSetH elper(FrameSecu rityDescriptor
secDesc, PermissionSet demandSet, PermissionSet& alteredDemandSe t)
at
System.Runtime. Serialization.F ormatterService s.nativeGetSafe UninitializedOb ject(RuntimeTyp e type)
at
System.Runtime. Serialization.F ormatterService s.GetSafeUninit ializedObject(T ype type)
--- End of inner exception stack trace ---

Server stack trace:
at
System.Runtime. Serialization.F ormatterService s.GetSafeUninit ializedObject(T ype type)
at
System.Runtime. Serialization.F ormatters.Soap. ObjectReader.Pa rseObject(Parse Record pr)
at
System.Runtime. Serialization.F ormatters.Soap. ObjectReader.Pa rse(ParseRecord
pr)
at System.Runtime. Serialization.F ormatters.Soap. SoapHandler.Sta rtChildren()
at System.Runtime. Serialization.F ormatters.Soap. SoapParser.Pars eXml()
at System.Runtime. Serialization.F ormatters.Soap. SoapParser.Run( )
at
System.Runtime. Serialization.F ormatters.Soap. ObjectReader.De serialize(Heade rHandler handler, ISerParser serParser)
at
System.Runtime. Serialization.F ormatters.Soap. SoapFormatter.D eserialize(Stre am
serializationSt ream, HeaderHandler handler)
at
System.Runtime. Remoting.Channe ls.CoreChannel. DeserializeSoap RequestMessage( Stream inputStream, Header[] h, Boolean bStrictBinding, TypeFilterLev
el securityLevel)
at
System.Runtime. Remoting.Channe ls.SoapServerFo rmatterSink.Pro cessMessage(ISe rverChannelSink Stack sinkStack, IMessage requestMsg, ITransportHeade r
s requestHeaders, Stream requestStream, IMessage& responseMsg,
ITransportHeade rs& responseHeaders , Stream& responseStream)

Exception rethrown at [0]:
at System.Runtime. Remoting.Proxie s.RealProxy.Han dleReturnMessag e(IMessage
reqMsg, IMessage retMsg)
at System.Runtime. Remoting.Proxie s.RealProxy.Pri vateInvoke(Mess ageData&
msgData, Int32 type)
at SI_Remoting.Rem oteMessage.SetC lient(String xmlFileName, IClient
client) in
c:\_dev\dotnet\ si_proxy\si_rem oting\si_remoti ng\remotemessag e.cs:line
33
at SI_Client.Clien t.RegisterNewMs g(String xml) in
c:\_dev\dotnet\ si_proxy\si_cli ent\si_client\c lient.cs:line 35
at SI_Client.Clien t.Main(String[] args) in
c:\_dev\dotnet\ si_proxy\si_cli ent\si_client\c lient.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.publi c.dotnet.langua ges.csharp/<01************ *************** *******@microso ft.com>

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.S erializationExc eption:
Because of security restrictions, the type System.Runtime. Remoting.ObjRef ca
nnot be accessed. ---> System.Security .SecurityExcept ion: Request failed.
at
System.Security .SecurityRuntim e.FrameDescSetH elper(FrameSecu rityDescriptor
secDesc, PermissionSet demandSet, PermissionSet& alteredDemandSe t)
at
System.Runtime. Serialization.F ormatterService s.nativeGetSafe UninitializedOb ject(RuntimeTyp e type)
at
System.Runtime. Serialization.F ormatterService s.GetSafeUninit ializedObject(T ype 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
2916
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 use them. No IIS. Use TCP, binary. Standard server example with a console host and console client. .NET 1.1, windows XP. (I tried posting to the remoting newsgroup, no answers in the last couple days, trying here in hopes that more people watch this...
0
1533
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 that we want to send will be very straightforward. If one of the clients has changed some data, the other clients need to know about it. If the clients are not on line then the message may have to wait until they are on line. The messages
15
3972
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" type="Interfaces, IMyFirstRemotableObj" objectUri="ControlCenter" /> </service>
5
357
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 Remoting or a XML Webservice, and than write my Windows Forms application that uses it. and than maybe in the future the Webclient. I have jsut one question: I hate the performance/speed-problems with
10
5554
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 app might be using the same port. Is there an alternative way of communicating between 2 exes on the same machine? Thanks, Michael Culley
6
2707
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 rmi. Just to keep my question short I am posting trimmed version of my code. //file: Serializable.cs
3
1705
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 to maintain a constant thread (i.e. thread that polls the database and sends messages back to client when a certain record is found?). Thanks.
9
2093
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 example in the 101 VB.NET examples. It works great, only 1 instance ever gets created and is shared by each client. I have a few questions though, * Can the singleton contain events? In such a way that when the
2
1687
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 some software (currently it's essentially a single tier app - a giant meat ball - we're turning it into an n-tier architecture; gotta love ex-employees). One of the things we're looking at doing is using Remoting from the client to an appserver...
2
3049
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 / Server activated mode on startup. The Remoting Client accesses the Remoting Class through the interface of the Class and subscribes to an event of the Remoting Class that will be fired upon the private member value change.
0
8253
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8009
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8240
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5411
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3867
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1482
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1216
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.