|
Hello programmers,
I wrote a remoting server and a client. I use some basic Remoting techniques:
1) There is a class/interface (remote object) declaring the Functions, like "String SendCommand(String text) ". Lets call it RemoteObj (IRemoteObj ).
2) Then, I register a well-known Type:
RemotingConfiguration.RegisterWellKnownServiceType(<br />
typeof(RemoteObj), "RemoteServer",<br />
WellKnownObjectMode.Singleton);
Now there is my problem: When the client executes the method, then i need to handle it completely inside the RemoteObj since i dont have a reference to the registered Object instance. This is not what i want actually, because i have the whole ready application around the RemoteObj Object which is able to return the whole data needed. The Remote Server is just a part of my application, not the other way round.
Is there a possibility to reference the Singleton object instance? I even could imagine to handle the communication by delegates/events.
Can you help me?
Thanks in Advance!
|
|
|
|
|
Your question/problem is not very clearly stated....
however here is how I deploy remoting.
On the server side I have RemoteClass which inherits IRemoteEntity (I changed your name to avoid confusion)
On the remote side you should register IRemoteEntity NOT RemoteObj
On the client side you want to connect to the remote server asking for a type IRemoteEntity. All references on the client side work with the IRemoteEntity instead of the RemoteObj.
So now I have a reference via an instance variable in the client to my remote object which was defined
IRemoteEntity remoting;
Now I can do this:
string value = remoting.SendCommand( command );
All code is now executed on the remote server.
|
|
|
|
|
Ok thanks so far, but this is not exactly the problem, let me explain further.
You explained how to contact the Remoting Server from the Client, so lets continue from there.
The Server received the command String sent from the Client (from SendCommand Method. Now, everything happens in an instance of RemoteObj (which implements IRemoteEntity and MarshalByRefObject ).
But now, the RemoteObj needs information from the current instance of the Server Application which originally registered the Service (you remember my first post? ), which is the instance doing the actual work.
But i dont have any reference to the instance neither from the RemoteObj to the server application, nor the other way.
I hope, you can understand now.
Here is another very small example:
using System.Runtime.Remoting...
namespace MyService
{
public class SimServer
{
private int listeningPort = 17998;
private TcpChannel channel;
public int justATestVariable = 123;
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(MyService.ServerObj), "TheServer",
WellKnownObjectMode.Singleton);
}
public class ServerObj : MarshalByRefObject, IRemoteEntity
{
public String SendMessage(String message) {
}
}
}
Now, imagine the Server was started, therefore a single instance of MyService.ServerObj was created. Then, the method SendCommand was called from a client, and the Serving Object (ServerObj ) needs the current value of justATestVariable to be able to reply to the clients request.
Any advices?
Thank you!
|
|
|
|
|
Your class SimServer is usually called the Remoting Host. In all designs I've seen so far, the only purpose of the Host was setting up the Remiting environment and providing the process the Server (your class ServerObj) runs in. I've never tried to establish any communication between the Remoting Server object and its Host. Therefore, the following approach is just an idea and has not been tested.
If the Server and the Host exist within the same AppDomain of the Host's process, you may declare certain methods/properties of the Host static.
<br />
namespace MyService<br />
{<br />
public class SimServer<br />
{<br />
static public int justATestVariable = 123;<br />
}<br />
<br />
public class ServerObj : MarshalByRefObject, IRemoteEntity<br />
{<br />
int myCopy = SimServer.justATestVariable;<br />
}<br />
}<br />
Alternatively you can make the Host a singleton and access its only instance from your server object.
If the Server and the Host are placed in different AppDomains, things will become more complicated. You will have to set up a separate channel of communication between the two objects, e.g. using pipes. There are some articles here on CP about this topic.
|
|
|
|
|
Thanks Tim for your reply and your explainations
I really appreciate your help!
I understand your design approaches, but i want to clarify my approach here:
Looks like i run into that problem because the application was originally never designed to be a server, but we found out later, that it might be very handy to have it started on a server machine and be able to get the needed data by requesting it from a small client application. So the basic idea of the remoting server functionality was more just a plugin or addon feature to the main application, therefore, the main application became just a host and not the Remoting Server itself. It can run completely without the server, it has its own GUI, its even based on its GUI.
So this is the main reason why the - let me call it: "Remoting Server Plugin" needs most of its data from the host.
The idea to provide Static methods is maybe not cleanest design but it might be the easiest one. I have no idea how to make the Host a Singleton.
Well thanks again!
|
|
|
|
|
In C# it is really simple to create a Singleton. You don't have to use the double-checked locked accessor as it is used in C++ or Java.
public class Server
{
private static readonly Server _instance = new Server();
private Server()
{
}
public static Server Instance
{
get{ return Server._instance; }
}
}
Within your code you now must use Server.Instance instead of new Server() . Thus your "Server Host" and your "Remoting Plugin" will access the same object.
|
|
|
|
|
Hi,
I'm developing an asp.net application which logs error in case of exceptions.
When it logs error teh following message displayed in event log.
Error loading an Event Sink of type 'Microsoft.EnterpriseInstrumentation.EventSinks.LogEventSink'. The Event Source of name 'Application' will not write events out to this Event Sink. The following exception was returned during the load:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: An error occurred determining if the Windows Event Log source of Application (Loan) exists on machine .. This may be due to an incorrect machineName parameter. ---> System.Security.SecurityException: Requested registry access is not allowed.
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.SourceExists(String source, String machineName)
at Microsoft.EnterpriseInstrumentation.EventSinks.LogEventSink..ctor(IDictionary parameters, EventSource eventSource)
--- End of inner exception stack trace ---
at Microsoft.EnterpriseInstrumentation.EventSinks.LogEventSink..ctor(IDictionary parameters, EventSource eventSource)
--- End of inner exception stack trace ---
at System.Reflection.RuntimeConstructorInfo.InternalInvoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at Microsoft.EnterpriseInstrumentation.EventSinks.EventSink.CreateNewEventSinks(DataRow[] eventSinkRows, EventSource eventSource)
Can you please help me in this.
thanks in advance
Priya
|
|
|
|
|
I have had this problem using the Enterprise Library... it a matter of rigths over the register...
if you do it with a win application ( just for testing ) you'll see that no error is written in the Event Log... because the Win Applications runs with the Credentials of the user is logged in the machine... but the ASP.NET user doesn't have this rigths... you have to give the ASP.NET user rigths to write in the Event Log.
Regards
Ricardo Casquete
|
|
|
|
|
How would programatically change the NotifyIcon icon while a program is running. Like say I had an email checking program that ran down in the system tray but I wanted the icon to change from black to green if I have an email waiting? Or better yet display a number that is the quanitity of unread email messages on the server. Is there a away to do this without having a 99 .ico files somehwhere on the file system that are loaded when needed.
In other words is there a way to dynamically generate an icon file on the fly and then use it as the NotifyIcon?
|
|
|
|
|
|
Does anyone have some good samples of Serializing a parent object that has child objects that in
turn may have child objects. I can serialize the parent but it doesnt like what I am doing with the children unless I make them an array. At least I think it likes the array. I would like to keep the children in an ArrayList or Generic List<child>. I have one example but it uses a Hashtable and I am not sure the sample will translate into what I am doing.
|
|
|
|
|
What are you using to serialize the object graph? The XmlSerializer? The BinaryFormatter? SoapFormatter? The different serialization techniques have different requirements/constraints.
Josh
|
|
|
|
|
I would like to serialize it to XML so I am using the XmlSerializer. It serializes the parent but chokes on the the children. I have some code but it is not quite what I am doing. Any other help would be appreicated.
|
|
|
|
|
Without the actual error message it's hard to say what the problem is. But, here are some things to keep in mind about the XmlSerializer:
1) It does not serialize object graphs with circularites (A references B, and B directly or indirectly references A). It makes exceptions to this rule for a select few classes in the .NET framework, such as the DataSet, but that doesn't help the rest of us.
2) As 'theRealCondor' mentioned, it only serializes public get/set properties of an object. (It also will serialize public fields, but those should never exist!)
3) There are some attributes you can use to control how the serialization of sub-objects is performed (this might be relevant to your issue, somehow).
Here's a great tutorial on everything you would ever want to know about the XmlSerializer: http://www.topxml.com/xmlserializer/[^]
I hope that helps,
Josh
|
|
|
|
|
If you are using XmlSerializer all properties must be public. I'm not sure about how it walks the properties within the child.
If the class is not public or you have private data, then you need to inherit ISerializable as well as IDeSerializableCallBack and handle the serialization manually. There are articles on MSDN that describe how to do this.
|
|
|
|
|
Hello,
I have a crystal report which contains a subreport. That subreport does not
show the result of the formula field when the main report is displayed,
although it does show if the subreport is displayed by itself.
The formula is valid (and I have tried this with much simpler formulae
without success).
I am using object collections to populate the report and subreport,
extending the example given in MSDN.
<br />
List<DirectConsumerLoan_Helper> ds = new List<DirectConsumerLoan_Helper>();<br />
List<Sub_Parties_Helper> dsBorrowers = new List<Sub_Parties_Helper>();<br />
<br />
rpt.Load(".\\Reports\\DirectConsumerLoan.rpt");<br />
rpt.SetDataSource(ds);<br />
<br />
CrystalDecisions.CrystalReports.Engine.ReportDocument subrpt =<br />
rpt.Subreports["Sub_Parties.rpt"];<br />
subrpt.SetDataSource(dsBorrowers);<br />
<br />
<br />
_Main.OpenReportViewer(rpt);
I am using VS2005.
|
|
|
|
|
In desperation I solved this by vertically resizing the formula field!
Remakrably when I shrunk it back to its previous size it still worked. The inner mysteries of Crystal!
|
|
|
|
|
I'd like to host a custom usercontrol inside of a DataGridViewHeaderCell ... I made an attempt @ extending the DataGridViewHeaderCell, and I tried to add it into a table, but this led me nowhere. Could anyone tell me how I can go about adding a control (which in turn contains buttons and checkboxes) to a DataGridViewHeaderCell. I really can't seem to figure it out ... the samples provided by Microsoft only demonstrate how to add something that inherits from a simple control such as textbox or a calendar (datetimepicker).
Anyone know of a good way of doing this?
Thanks in advance,
|
|
|
|
|
I recently found a post on Microsoft's Forums that suggested using custom painting, but that just seems too hairy to get involved with. All I want to do is add 4 buttons (contained in one user control) to a DataGridView HeaderCell. Microsoft said that you can't do this because it won't support hosting a panel inside of the cell. It just seems strange to me that no one else has tried to do this and succeeded ... unless I just haven't found it yet. My second thought is that I could make a control consisting of a DataGridView and several "FakeColumns" that would contain the buttons and upon clicking them would trigger changes to the DataGridView, which would not have HeaderCells. Idea is below ... suggestions/comments welcome and needed desperately. Thanks again.
*** = Panel containing my controls and HeaderText Labels for column names
+---+ = DataGridView (standard MS-built .NET 2.0 control)
| | |
+---+
| | |
+---+
*************************************************************
* Column Name * Column Name2 * Column Name3 *
* * * *
* [user control] * [user control ] * [user control] *
*************************************************************
| data | data | data |
+-----------------------------------------------------------+
| data | data | data |
+-----------------------------------------------------------+
| data | data | data |
+-----------------------------------------------------------+
|
|
|
|
|
Hi,
I'm looking for a small C# code sample (client and server) on how to do the following (if at all possible):
1. Have a client connect to a server using WSE2.0 using a TCP socket (not http)
2. Have the connected server send a message to the client without the traditional preliminary client request.
My understanding is that this is completely possible with WSE2.0. To date, we have a client/server app that has to poll the server for more information using standard HTTP webservices, but we are looking to optimize this by simply letting the server tell the client when there is new information and proactively send it.
Can anyone point me to a sample code or whip something up quickly?
Thanks!
take care,
Jasen
|
|
|
|
|
|
Hi ppl,
I need a help!
I try to make a program that can define the contours and verctorise a geometric shape in a bitmap image.
If someone know any algorithm that do it, or have the solution to my problem please contact me!
PS: Sorry my writen english, i'm Portuguese
MD - mdfixe@gmail.com
|
|
|
|
|
|
Thks for the answer
I already make that, now that i want is trace vectorize(with lines) the image contours that was defined after applied this filter
Thanks
MD
|
|
|
|
|
You are more likely to get an answer in a Flash forum rather than a C# forum.
|
|
|
|