I have written a WCF service application and a class library (Logger.dll
). I have written the code using a publish - subscribe pattern.
In the class library, pushing data as by publishing using delegates and events. And it is getting the data by subscribing the events in the WCF service application. So after hosting the service application, I need to push the data from WCF service to another console application. How can I push data while subscribing the events in the WCF service to another console application?Anyone know how to do this?
Logger.dll
public class Data
{
public string ID { get; set; }
public string Description { get; set; }
}
public delegate void LogHandler(Data log);
public class ClsSub
{
public event LogHandler OnDataRetrieved;
public void LoadData()
{
DataTable dt = GetData();
foreach (DataRow row in dt.Rows)
{
Data logdata = new Data();
if (row["Description"].ToString().Contains("User found"))
{
logdata.ID = row["UserID"].ToString();
logdata.Description = row["Description"].ToString();
}
if (row["Description"].ToString().Contains("User not found"))
{
logdata.ID = row["UserID"].ToString();
logdata.Description = row["Description"].ToString();
}
if (OnDataRetrieved != null)
{
OnDataRetrieved(logdata);
}
}
}
private DataTable GetData()
{
var result = new DataTable();
result.Columns.Add("UserID", typeof(string));
result.Columns.Add("Description", typeof(string));
result.Rows.Add("user1", "description1");
result.Rows.Add("user2", "description2");
return result;
}
}
public class ClsMain
{
public event LogHandler OnDataRetrieved;
public void ReadData()
{
ClsSub sub = new ClsSub();
sub.OnDataRetrieved += OnDataRetrieved;
sub.LoadData();
}
}
WCF Service
Iservice1.cs
Using Logger;
[ServiceContract(CallbackContract = typeof(IDataServiceCallBack))]
public interface IDataService
{
[OperationContract(IsOneWay = true)]
void RetrieveLogData();
}
[ServiceContract]
public interface IDataServiceCallBack
{
[OperationContract(IsOneWay = true)]
void OnLoggerData(Data log);
}
Service1.svc.cs
public class Service1 : IDataService
{
public IDataServiceCallBack callBack
{
get
{
return OperationContext.Current.GetCallbackChannel<IDataServiceCallBack>();
}
}
public void RetrieveLogData()
{
ClsMain main = new ClsMain();
main.OnDataRetrieved += ClsMain_OnDataRetrieved;
main.ReadData();
}
private static void ClsMain_OnDataRetrieved(Data log)
{
// I am getting the data when the publisher publishes something.
// I need to send this data to another console application.
//Console.WriteLine(log.ID + " " + log.Description);
}
}
I am getting the data when the publisher publishes something and the subscriber subscribes to the event in the WCF service. Is it possible to push this data to another console application?Is anyone know how to do this?