0

How to Write a WCF service method which should accept the logs as a collection in C# ? My WCF service should accept the collection of log messages and then we have to insert into the DB.

Thanks !!!

  • Who is this "the logs"? – Matten Aug 13 '13 at 07:39
  • Create a service method that has a parameter for the collection of logs, then in the service method iterate through the collection and insert the data into the database. – Tim Aug 13 '13 at 07:45
  • Hi Tim, can u please provide the psudo code, so that i will have an idea? – Suchai Tammewar Aug 13 '13 at 09:37
  • Logs are nothing but it may be the info/error/warning, for example: suppose from UI if they are planning to send 10 log messgages to our Service, then service should accept all those messgaes and we have to iterate and then we have to insert the records into the DB . – Suchai Tammewar Aug 13 '13 at 09:39

1 Answers1

0

You can implement that simply as follows: ( you might add yourself any other parameters you want to the service method including service headers)

[DataContract]
 public class LogData
 {
    [DataMember]
    public long LogId { get; set; }
    [DataMember]
    public string LogMessage { get; set; }
 }

[ServiceContract]
public interface ILoggerService
{
    [OperationContract]
    void SaveLogs(List<LogData> logs);      
}

public class LoggerService : ILoggerService
{
    public void SaveLogs(List<LogData> logs)
    {
       // write your DB specific logic to loop through the logs object and store into the db.
    }
}
Alagesan Palani
  • 1,984
  • 4
  • 28
  • 53