473,386 Members | 1,699 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,386 software developers and data experts.

.NET 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 files can be rejected for many reasons so we
would like to inform the user whether his changes have been done 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).

There might be a better way of doing this but I don't see it. With basic
..NET Remoting, I could do it by having the client wait for the IS to answer
and then send that answer to the client but since I have no idea how long
that could take, It's not a good option.

Thanks a lot in advance for all your help,

Skip.
Nov 16 '05 #1
3 1448
Sounds like something that typically calls for MSMQ although remoting is
also possible but if you are new to remoting MSMQ is much easier. Otherwise,
try Ingo Rammer's book on remoting a try.
Nov 16 '05 #2
When the client submits work to the server, why not have them supply an interface to othemselves at the same time. So the remote method would look something like:

void Submit(string doc, INotifyClient);

and INotifyClient is implemented by the client and looks like this:

interface INotifyClient
{
void WorkCompletedSuccessfully();
void WorkInError(int errorcode);
}

or something like that. Now when teh work is enqueued for processing (Submit returns) the client cal get on with their own thing. The server enqueues not only the doc but, packaged with it, the interface to the client that submitted the work. When the work is dequeued it is processed and the client informed of the outcome via the interface. The only thing you will need to do in the client is create a Channel like this (doesn't matter which channel btw)

TcpChannel chan = new TcpChannel(0); // will set this up on a free port on the client
ChannelServices.RegisterChannel(chan);

The server doesn't need to know what port the client is listening on or where the client is *explicitly* as this information will be passed as part of the submit message as the interface is marshalled.

Two things to note:

1) the call from the server will come on a threadpool thread and so you have to be careful of multithreading issues.
2) This will have issues if there is a firewall in the network topography

Regards

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

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<70**********************************@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).

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 files can be rejected for many reasons so we
would like to inform the user whether his changes have been done 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).

There might be a better way of doing this but I don't see it. With basic
.NET Remoting, I could do it by having the client wait for the IS to answer
and then send that answer to the client but since I have no idea how long
that could take, It's not a good option.

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.770 / Virus Database: 517 - Release Date: 27/09/2004

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

I finally had time to try what you suggested but I'm getting all sort of
exceptions because my classes and proprties are not serialized correctly
(that's my hypothesis).

Here's part of my code:

<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)
{
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 have no idea what to try next.

Any help would be greatly appreciated.

Thanks, Skip.

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...
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"...
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...
9
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"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.