Click here to Skip to main content
15,905,566 members
Home / Discussions / C#
   

C#

 
GeneralRe: .NET and "industrial espionage" Pin
Palladino12-Feb-04 5:42
Palladino12-Feb-04 5:42 
GeneralTesting .NET remote connection Pin
naxos10-Feb-04 3:53
naxos10-Feb-04 3:53 
GeneralRe: Testing .NET remote connection Pin
Marc Clifton10-Feb-04 4:10
mvaMarc Clifton10-Feb-04 4:10 
GeneralCannot abort thread Pin
Mertli Ozgur Nevres10-Feb-04 3:38
Mertli Ozgur Nevres10-Feb-04 3:38 
GeneralRe: Cannot abort thread Pin
Marc Clifton10-Feb-04 3:59
mvaMarc Clifton10-Feb-04 3:59 
GeneralRe: Cannot abort thread Pin
Kentamanos10-Feb-04 6:04
Kentamanos10-Feb-04 6:04 
GeneralRe: Cannot abort thread Pin
Marc Clifton10-Feb-04 6:24
mvaMarc Clifton10-Feb-04 6:24 
GeneralRe: Cannot abort thread Pin
David Stone10-Feb-04 9:06
sitebuilderDavid Stone10-Feb-04 9:06 
GeneralRe: Cannot abort thread Pin
Marc Clifton10-Feb-04 9:38
mvaMarc Clifton10-Feb-04 9:38 
GeneralRe: Cannot abort thread Pin
David Stone10-Feb-04 10:36
sitebuilderDavid Stone10-Feb-04 10:36 
GeneralRe: Cannot abort thread Pin
Marc Clifton10-Feb-04 13:40
mvaMarc Clifton10-Feb-04 13:40 
Questionhow to draw a X coordinate with a series of datetime data? Pin
Member 185560810-Feb-04 3:22
Member 185560810-Feb-04 3:22 
AnswerRe: how to draw a X coordinate with a series of datetime data? Pin
Alex Korchemniy10-Feb-04 7:20
Alex Korchemniy10-Feb-04 7:20 
Generalinteract 2 way Pin
Blue_Aqua10-Feb-04 3:14
Blue_Aqua10-Feb-04 3:14 
GeneralRe: interact 2 way Pin
Heath Stewart10-Feb-04 11:10
protectorHeath Stewart10-Feb-04 11:10 
GeneralRe: interact 2 way Pin
Blue_Aqua10-Feb-04 18:23
Blue_Aqua10-Feb-04 18:23 
GeneralMultyThreading in C#: Communication between threads Pin
Jasper4C#10-Feb-04 2:46
Jasper4C#10-Feb-04 2:46 
GeneralRe: MultyThreading in C#: Communication between threads Pin
Marc Clifton10-Feb-04 4:17
mvaMarc Clifton10-Feb-04 4:17 
GeneralRe: MultyThreading in C#: Communication between threads Pin
Jasper4C#10-Feb-04 12:08
Jasper4C#10-Feb-04 12:08 
GeneralRe: MultyThreading in C#: Communication between threads Pin
Marc Clifton10-Feb-04 13:38
mvaMarc Clifton10-Feb-04 13:38 
GeneralBackground compile in C# Pin
mufoxe10-Feb-04 2:24
mufoxe10-Feb-04 2:24 
GeneralRemoting, Events, Interfaces and Assemblies Pin
CyberHawke10-Feb-04 1:35
CyberHawke10-Feb-04 1:35 
Hello All,

I have an issue that is driving me crazy, no, not that kind of issue.

I have published an interface that I had intended to use to build objects for both client and server. The problem is, I cannot get my projects to recognize that I have declared an event, even though I can see it right there in the code.

A couple of scenarios:
1. If I don't declare an event, then I can use the published interface without any problems.
2. I can write the interface code directly in my project and again, no problem.

The problem with scenario one is that I need to declare events in my interface in order to be able to use them in both the client and the server.

The problem with scenario two is that now I am not publishing an interface, but rather declaring them in the code for both the client and the server objects. Crazy stuff eh Wink | ;)

This is my published interface which is compiled into a separate assembly:
using System;
using System.Data;

namespace RemoteObjectInterface {
public delegate void TaskCompleted();
public interface IRemoteObject {
event TaskCompleted TaskComplete; // event to be raised or captured

void StartTask();
string GetHostLocation();
DataTable GetProducts();
}
}

In a separate project, I make a reference to this assembly,
and then create a class that implements it:

using System;
using System.Data;
using System.Timers;
using System.Data.SqlClient;
using RemoteObjectInterface; // Reference to compiled assembly

namespace RemoteObject {
public delegate void TaskCompleted(object sender, TaskCompleteEventArgs e);
public class ProductsDB : MarshalByRefObject, IRemoteObject { // declared implementing interface
private static string _connectDef = "Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI;";
public event TaskCompleted TaskComplete;
private Timer tmr = new Timer();

public void StartTask() {
tmr.Interval = 10000;
tmr.Elapsed += new ElapsedEventHandler(tmrCallback);
tmr.Start();
}

private void tmrCallback(object sender, ElapsedEventArgs e) {
tmr.Enabled=false;
if (TaskComplete != null) {
TaskComplete(this,new TaskCompleteEventArgs("Task completed on server"));
}
}

// Get the data from the Products table in the Northwind database and return them to the client.
public DataTable GetProducts() {
string SQL = "SELECT * FROM Products";

// Create ADO.NET objects.
SqlConnection cnProducts = new SqlConnection(_connectDef);
SqlCommand cmdProducts = new SqlCommand(SQL,cnProducts);
SqlDataAdapter daProducts = new SqlDataAdapter(cmdProducts);
DataSet dsProducts = new DataSet();

// Execute the command and retrieve the data.
try {
cnProducts.Open();
daProducts.Fill(dsProducts,"Products");
}
catch(Exception ex) {
Console.WriteLine(ex.ToString());
}
finally {
cnProducts.Close();
}
return dsProducts.Tables[0];
}

public override object InitializeLifetimeService() {
return null;
}

// This method allows you to verify that the object is running remotely.
public string GetHostLocation() {
return AppDomain.CurrentDomain.FriendlyName;
}
}

[Serializable]
public class TaskCompleteEventArgs : EventArgs {
private string _result;

public string Result {
get{return _result;}
}

public TaskCompleteEventArgs(string result) {
this._result = result;
}
}
}

If you attempt to compile this code, you receive this error:
'RemoteObject.ProductsDB' does not implement interface member 'RemoteObjectInterface.IRemoteObject.TaskComplete'. 'RemoteObject.ProductsDB.TaskComplete' is either static, not public, or has the wrong return type.

and yet this code with the interface included in the same assembly compiles perfectly fine.

using System;
using System.Data;
using System.Timers;
using System.Data.SqlClient;

namespace RemoteObject {
public delegate void TaskCompleted(object sender, TaskCompleteEventArgs e);
public interface IRemoteObject {
event TaskCompleted TaskComplete;

void StartTask();
string GetHostLocation();
DataTable GetProducts();
}

public class ProductsDB : MarshalByRefObject, IRemoteObject {
private static string _connectDef = "Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI;";
public event TaskCompleted TaskComplete;
private Timer tmr = new Timer();

public void StartTask() {
tmr.Interval = 10000;
tmr.Elapsed += new ElapsedEventHandler(tmrCallback);
tmr.Start();
}

private void tmrCallback(object sender, ElapsedEventArgs e) {
tmr.Enabled=false;
if (TaskComplete != null) {
TaskComplete(this,new TaskCompleteEventArgs("Task completed on server"));
}
}

// Get the data from the Products table and return them to the client.
public DataTable GetProducts() {
string SQL = "SELECT * FROM Products";

// Create ADO.NET objects.
SqlConnection cnProducts = new SqlConnection(_connectDef);
SqlCommand cmdProducts = new SqlCommand(SQL,cnProducts);
SqlDataAdapter daProducts = new SqlDataAdapter(cmdProducts);
DataSet dsProducts = new DataSet();

// Execute the command and retrieve the data.
try {
cnProducts.Open();
daProducts.Fill(dsProducts,"Products");
}
catch(Exception ex) {
Console.WriteLine(ex.ToString());
}
finally {
cnProducts.Close();
}
return dsProducts.Tables[0];
}

public override object InitializeLifetimeService() {
return null;
}

// This method allows you to verify that the object is running remotely.
public string GetHostLocation() {
return AppDomain.CurrentDomain.FriendlyName;
}
}

[Serializable]
public class TaskCompleteEventArgs : EventArgs {
private string _result;

public string Result {
get{return _result;}
}

public TaskCompleteEventArgs(string result)
{
this._result = result;
}
}
}

This code compiles fine.
Am I missing something here?

John A Vonesh
Senior Developer
Tran-Tech Inc.

BAIT, n. A preparation that renders the hook more palatable. The best kind is beauty
GeneralRe: Remoting, Events, Interfaces and Assemblies Pin
Marc Clifton10-Feb-04 1:45
mvaMarc Clifton10-Feb-04 1:45 
GeneralReport Designer Pin
Itanium9-Feb-04 19:56
Itanium9-Feb-04 19:56 
GeneralRe: Report Designer Pin
Marc Clifton10-Feb-04 1:47
mvaMarc Clifton10-Feb-04 1:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.