|
Just one more doubt.
How do I pass the reference of the ListBox?
I have this:
- The DLL that has the remoting object. That object has a ListBox and a method that adds a string to the ListBox (this is the method called by the web service)
- The web service that has an instance of the remoting class (static)
- The application that receives the messages with the listBox. This application has an instance of the remote object.
- The client application that calls the web method.
This doesn't work because the two remote objects created are not the same, I guess. I tried to write a web method that receives a remote object to use that object, but I get an error.
How can I do that?
I'm finding too much problems here. Maybe I should use a console application instead
|
|
|
|
|
The Remoting object should, for example, accept a ListBox as a parameter in its constructor. When your application that displays the ListBox loads, instantiate the Remoting object passing an instance of the ListBox to which messages are added. You then programmatically register the Remoting object as a WKO, which is discussed in the .NET Remoting documentation in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm sorry but I can't make it work. I tried to follow your instructions:
1) I have the remote object:
public class MessageWin: MarshalByRefObject
{
private string message= "Waiting messages...";
private ListBox l= new ListBox();
public ListBox L
{
set { l = value; }
get { return l;}
}
public string Message
{
get { return message;}
set { message = value;}
}
public void addMessage(string m)
{
mensaje = m;
l.Items.Add(message);
}
}
2) In the client app that should show the messages, just a blank form where I add:
public class Form : System.Windows.Forms.Form
{
private static MessageWin message = new MessageWin(); private System.Windows.Forms.ListBox listBox;
public Form()
{
InitializeComponent();
TcpServerChannel canal = new TcpServerChannel(8989);
ChannelServices.RegisterChannel(canal);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(MessageWin),"MessageWin",WellKnownObjectMode.Singleton);
}
// I drag a ListBox from the IDE and change that lines:
private void InitializeComponent()
{
this.listBox = message.L;
[...]
3) In the web service I have that:
public class ServRest : System.Web.Services.WebService
{
private static MessageWin m = new MessageWin();
private void RegisterChannel()
{
TcpClientChannel channel = new TcpClientChannel();
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownClientType(typeof(MessageWin), "tcp://localhost:8989/MessageWin");
}
[WebMethod]
public void sendMessage(string s)
{
m.addMessage(s);
}
4) Just another application that calls the sendMessage web method.
The application doesn't break but no messages are shown in the listBox. I guess the two remote objects are not the same. I tried passing the object to the web service but then I have problems adding the web reference...
Can you help me?
|
|
|
|
|
Again, your remote object class does not instantiate the ListBox but gets a reference to one instantiated and hosted by the Windows Forms application. If the remote object instantiates the ListBox itself, it can't post messages to the one in the Windows Forms application. It's a simple case of control references. You also can't host the ListBox you're incorrectly instantiating in your remote object because it would potentially run on a different thread and you can't add controls created on a different thread to your Form (or other container) when they were created on a different thread.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you for keeping helping me.
I don't understand your post. You say that my remote class gets a reference from the Windows forms application, but the code I posted before shows that the remote class creates a new ListBox and the Windows Forms app just gets the remote class one: listBox = message.L;
I think the problem comes because in the web service I declare a new remote object, different from the Windows application one.
What part of my code would you change?
|
|
|
|
|
Yes, the remote object should get an instance of the ListBox declared and initialized in the Windows Forms application. As I mentioned before, if you use the ListBox from the remote object, you could very easily run into many problems since the remote object would be created on a different thread depending on the activation type. Controls cannot host other controls created in a different thread and often times even calling methods or getting/setting properties on controls created in different threads causes problems, which is why Control.Invoke and Control.InvokeRequired exist.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
OK, but I still have the problem. I have 3 applications. I changed my code to pass the ListBox to the remote object, but my web service also needs a remoting object. If I declare a new remote object in the web service, I have two different objects, and I need to work with the same one.
How can I do that? What do I have to change in the web service?
|
|
|
|
|
This is a very simple problem that you're making way to hard and making me repeat myself far too many times.
The remote object is hosted by the monitor application (or whatever it is). It IS the implementation. All other remoting clients - like your web service - simply proxy calls to the remoting object that adds strings to the ListBox declared and instantiated in your Windows Forms application. That application is what is hosting the remoting object. The web service - or any client app using the proxy - doesn't need to have a ListBox at all. It proxies calls to the remoting object via a shared interface or a generated proxy using soapsuds.exe or something. There's absolutely no reason to host the remoting object implementation separate from your monitor application.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It's finally solved
I am really sorry. I was making a concept error. As I said, I was declaring two remote objects. I was watching Remoting samples and that was wrong.
As you said, I only have to declare the remote object in the monitor, and send the ListBox, that is declared in the windows form app.
Then, in the web service I just get the object from the channel with the Activator.GetObject method.
Now I see my messages.
Thank you for your help.
|
|
|
|
|
Hi,
Can I use window.showmodal?
Sombody help me?
|
|
|
|
|
You mean Form.ShowDialog ? Yes, but you must dispose the Form when you don't need it anymore. Modal dialogs need to be disposed explicitly or you'll gradually consume more and more memory that won't be reclaimed because of native resources:
using (MyForm form = new MyForm())
{
form.ShowDialog();
} Using using this way ensures that even if an exception is thrown your modal form is disposed. See the .NET Framework SDK for the Form.ShowDialog method for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you for ask,
Sorry, but,
I need to know Who can i use "window.showmodal" in web appl.
|
|
|
|
|
Then you should be more specific about what you need. This question doesn't belong in this forum. Ask in the Web Development[^] forum.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks for your amiability and your time.
|
|
|
|
|
Hi all,
im having a small problem using an imagelist with a treeview. the problem is basically as follows. I add an imagelist and populate it with images (16x16 32bit) and i bind the imagelist to a treeview. so far so good, now if i add nodes to the treeview in code/designer time for a short while its ok, but after a while (a few compiles) the imagelist seems to break and the treeview nodes appear to have "blank" image.
The only way i can fix this is to manually delete the treeview and add it again with the imagelist.
Has anyone got a more practical solution to my problem?
many thanks,
Will
|
|
|
|
|
When you use the designer to add an ImageList , that ImageList is serialized to your .ResX file, which VS.NET uses by default (it's hidden; click Project-<Show All Files). There is a known issue where this can get corrupted. The solution is to remove the .ResX file - not your TreeView component - and re-add a .ResX file and then your ImageList . Your image indexes for the TreeNode s will still be correct so adding the new ImageList with images in the same indices will save you a lot of work.
This should be fixed in VS.NET 2005.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ive been asked to create a profile tool that interfaces with msn. It uses the events generated by msn to build up a users profile. What language would people recommend I use, and reasoning. Ive seen this dotMSN libary in C#. would people say this is the best way to go about this task??
any suggestions greatly appreciated.
mikey
|
|
|
|
|
"Best way" is a matter of opinion. If you like the dotMSN code and don't mind installing the .NET Framework on whatever machine(s) need to build profiles, go for it.
Accessing the Windows Messenger/MSN Messenger APIs is done through COM, so any language that can server a COM client (and there's many!) can do it. If you don't want to worry about the 20+ MB .NET Framework installation, you could use VB6 which would be pretty easy as well.
Keep in mind that the Messenger APIs change quite a bit from major version to major version. That alone can make what you want to do a pain. Perhaps they have finally settled on an object model and will only version new interfaces from here on out. One can only hope.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
OK. I'm working on my first C# windows app. It has a couple of forms as well as a LOGIN FORM. The LOGIN FORM pops up at Application.Run() and requires the user to select a SQL Server in which to connect and enter a userid and password.
Where/How would be the best place to store this dynamic connection information so that I may reuse it later on for subsuquent database connections. An important note is that the app needs to be able to perform different tasks on different databases on that sql server once the user is connected.
MITA
|
|
|
|
|
One common method is to have a static collection property on some class that all your code can access like so:
public sealed class DB
{
private static SqlConnection connection;
private static object syncRoot = new object();
public static SqlConnection Connection
{
get
{
if (connection == null)
lock (syncRoot)
if (connection == null)
connection = new SqlConnection(
ConfigurationSettings.AppSettings["ConnectionString"]);
return connection;
}
}
} The caller is still responsible for opening and closing the connection, but you should leave it that way so you don't leave connections open longer than you have to. This can degrade performance (and limit connections too much) on your database server. Also note that I use SqlConnection only as an example. You could use any connection class, or even the ADO.NET interface IDbConnection if you wanted to. The latter idea would fit nicely with using a provider pattern.
I also used an example where the connection string is placed in the appSettings section of your app's .config file, which is also another good idea.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I try sending a message to a queue and AppSpecific contains the type of my message, the body is object of a class (Order). and i set formater for the queue.
_mq.Formatter = new XmlMessageFormatter(
new Type[] { typeof(Order) });
When I receive a message from the queue, I just got the body, not the info in AppSpecific field.
I tried to set
DefaultPropertiesToSend.AppSpecific
but don't know which info should i give to it.
If i send AppSpecific along with the message body do i have to change the formater to receive AppSpecific or just leave
it the same as above.
Could anyone here show me how to solve this problem.
Thanks,
Huy
|
|
|
|
|
Hello,
Can anybody tell me how to use serial communications rs232 and rs485 in the .net compact framework. I found some commercial links, but is there not a cheaper solution?
Thanks,
Jelle
|
|
|
|
|
|
Can anybody tell me how to hide the taskbar (with windows icon on the left down corner) in the .Net compact Framework?
Please help.
Jelle
|
|
|
|
|
I've never written for Windows CE or using the .NET CF, but I think you might want to check into P/Invoking this[^] API call.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|