"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:%2****************@TK2MSFTNGP04.phx.gbl...
Sure. Are there any particular parts that you're looking for help with?
There's good support in .NET for all of the primitive bits that you'd need
to build this.
Given the kind of application you're describing, I'd think you'd want to
write metrics to something like an MSMQ queue, not just a simple IPC
queue, since then you'd get fault tollerance, crash recovery, and so on
"for free" (of course, nothing's ever free). You could also use a SQL
Server table, or if you're using SQL Server 2005, you could use SQL Server
notification services (son of MSMQ) to queue the message to another
process or thread.
-cd
I am including a sample of what I have in mind if I do it in code rather
than MSMQ. I still have questions on:
1. Garbage collection since this is a web service. Will it only occur on
server reboot?
2. How should I control the thread. Should it just loop until the server is
rebooted as well?
3. Do I need a lock on the Queue object or is it enherintly threadsafe for
enqueue/dequeue?
CODE SAMPLE
[WebService(Namespace = "http://mycompany.com/b2bTestservices")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class TestServices : System.Web.Services.WebService
{
Queue<TestTxnMetricsmetricsQueue = new Queue<TestTxnMetrics>();
static readonly TestServices instance = new TestServices(); public
static TestServices Instance { get { return instance; } }
static TestServices() { }
TestServices()
{
Thread thread = new Thread(new ThreadStart(UpdateTestBAM));
thread.Name = string.Format("UpdateTestBAM{0}", 0);
thread.Start();
}
[WebMethod]
public XmlDocument OrderTestCert(XmlDocument doc)
{
TestTxnMetrics metrics = new TestTxnMetrics();
metrics.TxnStart = DateTime.Now;
ITestOrder rObj =
(ITestOrder)Activator.GetObject(typeof(ITestOrder) ,
ConfigurationManager.AppSettings["TestRemotingServer"]);
string ret = rObj.PlaceTestOrder(doc.InnerXml, metrics);
XmlDocument retxml = new XmlDocument();
retxml.InnerXml = ret;
metrics.TxnEnd = DateTime.Now;
lock (this) { metricsQueue.Enqueue(metrics); }
return retxml;
}
private void UpdateTestBAM()
{
//loop this and sleep between loops. but how do I terminate it?
FloodTxnMetrics metrics = metricsQueue.Dequeue();
}
}