我想從我的客戶端應用程序發送一條消息給我的WCF服務對於一個給定的時間跨度 什麼是我想要找出多少次打電話給我WCF服務被客戶端擊中。如何找到一個WCF服務多少次由客戶端
這裏是一個客戶端應用程序:
var messages = new String[1];
messages[0] = "My simple request";
var client2 = new Operator();
var startTime = DateTime.Now;
var timeoutSpan = TimeSpan.FromMinutes(.06);
var count =0;
while ((DateTime.Now - startTime) <= timeoutSpan)
{
foreach (string message in messages)
{
txtRequest.Text = message;
sendMessageResult = client.sendMessage("02", txtRequest.Text);
count++;
}
}
// this counts how many request I sent
textBox1.Text = count.ToString();
// this shows the server side count
textBox2.Text = client2.TotalHits().ToString();
這裏是我的WCF服務應用程序
編輯:
public byte sendMessage(string strMsgId, string strMessage)
{
byte result = 1;
try
{
if (strMsgId == "02")
{
lock (_lock)
{
++_count;
}
// Logging-------
// Build timestamp string
var currentDateTime = DateTime.Now;
string timeStampString = currentDateTime.ToString("yyyy-MM-dd hhmmssfff");
// Build filename for Inbound messages, concat timestamp and .txt extension.
string debugFileName = "C:\\Inboundmessage" + " " + timeStampString + ".txt";
var inboundMessageLog = new StreamWriter(debugFileName, false, System.Text.Encoding.Default);
// Write to the file:
inboundMessageLog.WriteLine(DateTime.Now);
inboundMessageLog.WriteLine("Time = {0}", currentDateTime.ToString("yyyy-MM-dd hh:mm:ss:fff tt"));
inboundMessageLog.WriteLine("{0}{1}{2}", "Inbound Message:", Environment.NewLine, strMessage);
inboundMessageLog.WriteLine("{0}{1}", "count:", _count);
inboundMessageLog.Close();
// --------------
result = 0;
}
}
catch
{
//Failed
result = 1;
}
return result;
//這裏是一個計數方法
public int TotalHits()
{
return _count;
}
我看到日誌的計數> 0,但爲什麼在客戶端上我沒有看到變化,當我打電話TotalHit方法?
你只關心這個被稱爲或這是由某些特定的客戶調用的,您必須記錄一些審計數據? –
這是我的客戶打電話,我想記錄審計數據 – HXD
看到這個[WCF可擴展性 - IOperationBehavior文章(http://blogs.msdn.com/b/carlosfigueira/archive/2011/04/12/wcf-可擴展性 - ioperationbehavior.aspx) –