Click here to Skip to main content
15,882,113 members
Articles / DevOps / Load Testing

Measuring and Monitoring WCF Web Service Performance

Rate me:
Please Sign up or sign in to vote.
5.00/5 (17 votes)
4 Oct 2012GPL310 min read 55.3K   2.2K   47  
Using ServiceMon to obtain performance statistics for web services
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Kaleida.ServiceMonitor.Model;
using Kaleida.ServiceMonitor.Model.Runtime;

namespace Kaleida.ServiceMonitor.UI.NotificationPanels
{
    public partial class ResponsesNotificationPanel : UserControl, INotificationPanel
    {
        private Monitor monitor;

        public ResponsesNotificationPanel()
        {
            InitializeComponent();
        }

        public void Initialise(Monitor monitorApplication)
        {
            monitor = monitorApplication;
        }

        private LimitedList<RequestResult> DataSource
        {
            get { return chkErrorsOnly.Checked ? monitor.RecentErrors : monitor.RecentResponses; }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            DataSource.Items.Clear();
        }

        public string PanelName
        {
            get { return "Responses"; }
        }

        public Control GetPanelControl()
        {
            return this;
        }

        public void RefreshContent()
        {
            lblItemLimit.Text = DataSource.Summary();

            var source = GetDataSourceListCopy();

            lock (lbRecentRequests)
            {
                SyncListBox(source);
            }
            Invalidate();
        }


        private void SyncListBox(IList<RequestResult> dataSource)
        {
            var superfluousListItems = lbRecentRequests.Items.Cast<RequestResult>().Where(i => !dataSource.Contains(i)).ToList();

            foreach (var superfluousListItem in superfluousListItems)
            {
                lbRecentRequests.Items.Remove(superfluousListItem);
            }

            var missingListItems = dataSource.Where(i => !lbRecentRequests.Items.Contains(i));
            lbRecentRequests.Items.AddRange(missingListItems.Cast<object>().ToArray());
        }

        private void btnCopyToClipboard_Click(object sender, EventArgs e)
        {
            var source = GetDataSourceListCopy();

            var content = new StringBuilder("SentOn\tDuration\r\n");

            foreach (RequestResult result in source)
            {
                content.AppendLine(result.ToClipboardItemText());
            }
            
            Clipboard.SetText(content.ToString(), TextDataFormat.Text);
        }

        private IList<RequestResult> GetDataSourceListCopy()
        {
            lock (DataSource)
            {
                return DataSource.Items.ToList();
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Architect BlackJet Software Ltd
United Kingdom United Kingdom
Stuart Wheelwright is the Principal Architect and Software Developer at BlackJet Software Ltd.

He has over 16 years commercial experience producing robust, maintainable, web-based solutions and bespoke systems for Microsoft platforms.

His latest project is Shopping UK, an elegantly simple shopping list for iPhone.

Comments and Discussions