Skip to content

Instantly share code, notes, and snippets.

@serkanince
Last active May 30, 2016 07:48
Show Gist options
  • Save serkanince/b3fb8a4853d8fe9f8bb2bb75035b6580 to your computer and use it in GitHub Desktop.
Save serkanince/b3fb8a4853d8fe9f8bb2bb75035b6580 to your computer and use it in GitHub Desktop.
Wcf Ping App
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
namespace Sample02_Wcf_Check_App
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Program Start... \n---------------------");
Console.WriteLine("Pinging : [ http://sampleservice.com/WinService.svc/IsAlive ] \n---------------------"); // //replace service link
Thread thread = new Thread(new ThreadStart(CheckWcfStatus));
thread.Start();
Console.ReadLine();
}
static void CheckWcfStatus()
{
Thread.CurrentThread.IsBackground = true;
try
{
//süreyi ölçmek adına
var swatch = Stopwatch.StartNew();
while (true)
{
swatch.Start();
using (var client = new System.Net.WebClient())
{
client.Encoding = System.Text.Encoding.UTF8;
var responseString = client.DownloadString("http://sampleservice.com/WinService.svc/IsAlive"); //replace service link
Console.WriteLine("Service Is Alive : " + responseString + " - Total Second : " + swatch.Elapsed.Seconds.ToString());
}
swatch.Stop();
swatch.Reset();
Thread.Sleep(new TimeSpan(0, 20, 0));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
}
}
//Sample service code
public class WinService : IWinService
{
public bool IsAlive()
{
return true;
}
}
[ServiceContract]
public interface IWinService
{
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "IsAlive")]
bool IsAlive();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment