|
After many hours of banging my head, I finally realized that the interface should of belonged to the class Entry point. Once I did this, I was able to do what I wanted. Here is a tidbit of the code I used.
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using RemoteInterfacecls; //Code not proviced at this time
using System.Runtime.Serialization;
namespace RemotingInterfaceServer
{
public class dataStuff
{
public byte [] mystuff;
}
public class EntryPoint
{
dataStuff dS = new dataStuff();
public static void Main(string[] args)
{
//Here is the initializaton
ds.mystuff = System.Text.Encoding.ASCII.GetBytes("This is a test");
TcpServerChannel channel = new TcpServerChannel(2566);
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(RemoteExample),
"RemoteExample", WellKnownObjectMode.SingleCall);
System.Console.WriteLine("Hit Key to Exit");
System.Console.ReadLine();
}
public class RemoteExample : MarshalByRefObject, IRemoteExample
{
public RemotingExample()
{
Console.WriteLine("Constructor Called ");
}
public IByteArray GetByteArray()
{
ByteArray byteArray;
byteArray.bytesRead = dS.mystuff;
return (IByteArray)byteArray;
}
}
[Serializable]
public class ByteArray : MarshalByRefObject, IByteArray
{
public byte [] bytesRead;
}
}
}
Tom McDaniel
|
|
|
|
|
Hello everyone , I'm in the process of writing a webservice for a small application im making, I lack a database so what im doing it making a folder on the server for each person that registers. I have a serperate folder in which when I am done will contain a text file for each member containing their password. I have completed the part of the webservice that creates a folder with the name they enter but when I went to make the part that makes the text file for their password I get an error: "Cannot create an instance of the abstract class or interface 'System.IO.TextWriter'. For the life of me I cannot figure what is wrong. Can anyone give me a hand in finding the error? I figure it is a very obvious mistake, heres my method:
[WebMethod]
public void RegisterAccount(string Name, string Password)
{
string path = @"G:\ArtAccounts\"+Name;
System.IO.Directory.CreateDirectory(path);
TextWriter PassWriter = new TextWriter(@"G:\ArtAccountsPasswords\"+@"Name.txt");
PassWriter.WriteLine(Password);
PassWriter.Close();
}
|
|
|
|
|
TextWriter is an abstract base class use StreamWriter
[WebMethod]
public void RegisterAccount(string Name, string Password)
{
string path = @"G:\ArtAccounts\"+Name;
System.IO.Directory.CreateDirectory(path);
StreamWriter PassWriter = new StreamWriter(@"G:\ArtAccountsPasswords\"+@"Name.txt");
PassWriter.WriteLine(Password);
PassWriter.Close();
}
I have never wasted time worrying about such insignificant things. Keep your eye upon the donut and NOT upon the hole. - Bill Sergio about posting in the right forum. The Lounge - June 23, 2002
|
|
|
|
|
Haha I knew it was somthing obvious, Thank you!
|
|
|
|
|
I'm creating an undo feature here and having a slight amount of problem with copying from one point of memory to another.
I've got a stack that will stores a 'before' and 'after' copy of the object that is currently residing in a ArrayList.
pUndoFeature.OldFeature = (BaseFeature) pBaseFeature.Clone( );
pUndoFeature.NewFeature = pBaseFeature;
Now when I click 'undo', I need to copy the contents of the object from the OldFeature to the NewFeature. Since many classes derive from 'BaseFeature', it is undesirable to do a member copy operation for each class.
Is there a C# way of performing a shallow copy of the object from one pointer to another without Cloning into a brand new object?
Thanks as always!
|
|
|
|
|
|
/nod.
I know about the MemberWiseClone function, but it creates a new copy of the class. Was just hoping to copy over the data from one class to another. Wishing for a function like
object MemberWiseCopy( object )
|
|
|
|
|
er, do you mean like
void MemberWiseCopy(object fromObject, object toObject);
The point being to use an already instanciated object instead of creating a brand new one inside the method?
|
|
|
|
|
Yes, that's exactly what I'm looking for.
Here's my save/undo feature. The function 'copy' is the one that I would like to replace with this 'mythical' function call.
public void Edited( BaseFeature pBaseFeature )
{
UndoFeature pUndoFeature = new UndoFeature( );
pUndoFeature.OldFeature = pBaseFeature.Clone( );
pUndoFeature.NewFeature = pBaseFeature;
pUndoFeature.Action = Actions.Edited;
pUndoFeature.Group = Group;
UndoList.Push( pUndoFeature );
}
public void Undo( ArrayList pFeatures )
{
UndoFeature pUndoFeature = null;
do
{
...
pUndoFeature = (UndoFeature) UndoList.Pop( );
switch( pUndoFeature.Action )
{
...
case Actions.Edited:
pUndoFeature.OldFeature.Invalidate( );
pUndoFeature.NewFeature.Invalidate( );
pUndoFeature.NewFeature.Copy( pUndoFeature.OldFeature );
break;
}
} while( pUndoFeature.Group == true );
}
}
|
|
|
|
|
Hallo!!!
So once again I have a problem....
This time i'm having trouble passing a reference of a form to an object, on the load_form event.
But this just gives me a blank reference....
How can I go around this?
|
|
|
|
|
I'm having trouble understanding what you're trying to do. Please post some code. And by blank do you mean null reference or do you have a watched variable that is showing up blank?
|
|
|
|
|
Well basicly what i've been doing is:
private void Form1_Load(object sender, System.EventArgs e)
{
//initiating a class (declared earlier=
defaultCls = new defaultClass(pictureBox1, form1.aktiveform);
}
//(only an example)
public class default
//construktor
public default(pictureBox pB, form frm)
{
// trying to use the frm reference...
}
Error message:
An unhandled exception of type 'System.NullReferenceException' occurred in CopyImage.exe
Additional information: Object reference not set to an instance of an object.
Well this must mean that the Form1 reference isn't set at this time, musn't it???
It works fine if I do the same, on f.x. a keypress event....
What I really was wondering about is if theres an event, which occurs after load complete.
f.x. OnLoadComplete(), or something like that????
|
|
|
|
|
I re-created what you gave me the best I could and it worked. I could not get any null reference exceptions.
The only thing I don't get is why your passing ActiveForm (assuming thats what you mean by "aktiveform") which may or may not actually be the form you want to reference.
|
|
|
|
|
So you are able to send a reference to an object (done when the OnLoad event occurs), and then use it in the object...
To be more precise, I tried to get the window location by saying:
//the frm = reference of Form1.AktiveForm
frmX = frm.Location.X
But that just throws an exception...
Ok so the problem could be that I'm sending the Form1.AktiveForm, you say... Yes that sound very likely because noone says that the form is Aktive (or in focus) at this time....
Then you said that you can't se the logic in me sending Form1.AktiveForm.... What shoudl I be sending???
If I try just to send Form1, the debugger says soemthing about a variable was expected????
...... so any ideas??? >
|
|
|
|
|
Heh....ehh... ups.... all I had to do was send a "this" pointer instead.... dooh.
Well I'm still new at c#, so I have an excuse
Anyway, thanks!!!
|
|
|
|
|
Hi,
I have a main window which is a MdiParent and to which i pop up a couple of other windows (on some event) as mdiChild using the show() method. I want each child window to appear at a particular position for which i use DockStyle properties.
But the new window which opens up resizes itself to the height or width of the original window depending on the dockstyle. I want the size of the mdichild form to remain as it is. What property should i set for this.
Also, In case there are more than one window which pops up,when i change the control from one window to another the position of the window changes. How to avoid this??
Thanks
Sripriya
|
|
|
|
|
simply setting the Location property doesn't work?
:wq
|
|
|
|
|
1.Choose "Microsoft OLE DB Provider for ODBC Drivers"
2.Choose "Use data source name" and select a alias from drop list.( The alias has no password)
3.Click "OK" button, but it shows "The .Net Data OLE DB Provider(System.Data.OleDb) does not support the MSDASQL Provider, Microsoft OLE DB Provider for ODBC Drivers.".
Thank you for your help!
I'm amumu, and you?
|
|
|
|
|
You have three options:
- If you're connecting to SQL Server, you could use the SQLConnection and related objects in the System.Data.SqlClient namespace;
- If you really need an OLEDB connection, use the OLE DB Provider for SQL Server (SQLOLEDB.1), or the equivalent for your data source;
- If you absolutely must have an ODBC connection, you need to download the ODBC provider for .Net and use that instead;
|
|
|
|
|
Thank you.
But I think the oleDbConnection should work properly when I do the steps as above, why does it reports error?
I'm amumu, and you?
|
|
|
|
|
The objects in System.Data.OleDb do not support ODBC connections, so you can't use the OLE DB Provider for ODBC. You have to use the ODBC .Net Provider to access an ODBC data source.
|
|
|
|
|
if u just wanna use access like me, just use a JET OLE DB connection. eg:
string jetConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\tracker.mdb";
accessConn = new OleDbConnection(jetConn);
hope it helps
|
|
|
|
|
|
Where can see the information?
I'm amumu, and you?
|
|
|
|
|
Either read the data in a OleDbDataReader or a OleDbDataAdapter. EG
string jetConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\tracker.mdb";
accessConn = new OleDbConnection(jetConn);
string query = "SELECT * FROM TABLE WHERE etc etc";
OleDbCommand myCommand = new OleDbCommand(query, accessConn);
OleDbDataReader myReader = myCommand.ExecuteReader();
while(myReader.Read())
{
string datain = myReader.GetString(0);
}
DataTable dt = new DataTable();
OleDbDataAdapter sda = new OleDbDataAdapter(query, accessConn);
sda.Fill(dt);
Hope this helps
|
|
|
|