Handling WCF Custom Exceptions when using ObjectDataSource

WCF uses a default SOAP exception called FaultException which allows for creating custom WCF Exceptions using the template FaultException<TDetail>. Exception Handling in WCF Web Service shows an example of creating and catching a custom FaultException error.

A difficulty with the example comes into play when using ObjectDataSource to bind to a WCF business object. The problem is that you cannot catch the exception in a try/catch statement like the example shows, so it will be an unhandled exception. ObjectDataSource, and other DataSource controls, don’t load data (or execute the select statement) until after Page_Load and other events have fired, so your try/catch in Page_Load won’t work. It seems the logic, which is forced upon you by ASP.Net, is that it ensures the data returned is up to date by executing all other events first. So in this case, errors from the WCF are going to flow to “special scopes” of the web application. Exception-handling in ASP.NET shows the various places errors can be handled. Let say the error will be handled by the Application_Error delegate in Global.asax. When the error flows to Global.asax, you have to use Server.GetLastError().GetBaseException() which you can put into an Exception object, but then you need to figure out the type to cast it into the correct exception. I could not find an example of how to do this, so I’m posting what I came up with.

Let’s say I have a custom WCF error called FaultException<SampleFaultException>. In my code I need to check if that is the error type. Here is the code in the Global.asax:


void Application_Error(object sender, EventArgs e)
{/* List of custom Exceptions from AddressService WCF
*
* System.ServiceModel.FaultException`1[SampleFaultException]
*/

//get the base error type
Type errType = Server.GetLastError().GetBaseException().GetType();

//get the generic base exception
Exception err = Server.GetLastError().GetBaseException();

//check the error type to later cast the exception
System.Text.RegularExpressions.Regex regSampleFaultException = new Regex(”SampleFaultException”);
System.Text.RegularExpressions.Match matchSampleFaultException = regSampleFaultException.Match(errType.ToString());

System.Text.RegularExpressions.Regex regFaultException = new Regex(”FaultException”);
System.Text.RegularExpressions.Match matchFaultException = regFaultException.Match(errType.ToString());

//process errors based on the exception

Response.Clear();

//check for SampleFaultException
if (matchSampleFaultException.Success)
{
Response.Write(”<pre>Start - This is a SampleFaultException</pre>”);

System.ServiceModel.FaultException<SampleFaultException> err3 = (System.ServiceModel.FaultException<SampleFaultException>)err;

Response.Write(”<pre>” + err3.Detail.errorcode + ” - ” + err3.Detail.message + “</pre>”);

Response.Write(”<pre>End - This is a SampleFaultException</pre>”);
}
//check for pure FaultException where is doesn’t have SampleFaultException
else if( (!matchSampleFaultException.Success) && (matchFaultException.Success))
{

Response.Write(”<pre>Start - This is a FaultException</pre>”);

System.ServiceModel.FaultException err3 = (System.ServiceModel.FaultException)err;

Response.Write(”<pre>” + err3.Message + “</pre>”);

Response.Write(”<pre>End - This is a FaultException</pre>”);

}

Server.ClearError();

}

List of Cognitive Biases

Perusing through cognitive biases. Here are a few culled from the list:

Dunning-Kruger effect — …when people are incompetent in the strategies they adopt to achieve success and satisfaction, they suffer a dual burden: Not only do they reach erroneous conclusions and make unfortunate choices, but their incompetence robs them of the ability to realize it. Instead, …they are left with the mistaken impression that they are doing just fine.

Fundamental attribution error — the tendency for people to over-emphasize personality-based explanations for behaviors observed in others while under-emphasizing the role and power of situational influences on the same behavior (see also actor-observer bias, group attribution error, positivity effect, and negativity effect).

Model Behavior from DSS to Work Relationships

The purpose of Decision Support Systems (DSS) are to help people overcome cognitive limitations and bounded rationality in decision-making so they can make more efficient and effective decisions. One of the main precepts in designing a Decision Support System is that it should be tailored to the decision-making style of the individual or group. To tailor a design, it is helpful to use a model of decision-making styles and behaviors.

Models are attempts to simplify reality. As such, not every context possible can be accounted for and processed in a model, so a model will always be imperfect. However by using a well researched and time-tested model, expected results can be inferred to some extent; in the case of DSS, its adoption and usefulness to users, user satisfaction, effectiveness, etc.. Table 1 and Table 2 are based on the Decision Style Inventory (DSI) developed by Alan Rowe who categorized types as Analytical, Conceptual, Directive, and Behavioral. Rowe’s DSI is derived from work by Carl Jung, and Jung’s work is the basis for other behavioral models such as Myers-Briggs. Typically, a person will have a strongly emphasized decision-making style with one or two backups (Marakas).

TABLE 1 - Decision Style Model



Complexity


Tolerance for Ambiguity
Analytical


  • Enjoys problem solving
  • Wants best answer
  • Thrives on control
  • Uses large volumes of data
  • Enjoys variety
  • Innovation
  • Uses great care in analysis


Conceptual

  • Achievement oriented
  • Generally broad outlook
  • Creative
  • Humanistic/artistic
  • Regularly initiates new ideas
  • Long term/futuristic thinker

Structure


Need for Structure

Directive

  • Expects results
  • Aggressive nature
  • Tends to react quickly
  • Relies heavily on rules
  • Intuitive in nature
  • Verbal communicator
Behavioral

  • Generally supportive
  • Very persuasive
  • Empathetic nature
  • Good communicator
  • Generally prefers meetings
  • Relies on limited data for analysis

Task/Technical
People/Social


 TABLE 2 - Common Characteristics of Decision Style Behaviors

Basic Style
Behavior under Stress
Motivation
Problem-Solving Strategy
Nature of Thought
Directive
Explosive, volatile
Power and status
Policies and procedures
Focused
Analytical
Focuses on rules
Challenge
Analysis and insight
Logical
Conceptual
Erratic, unpredictable
Recognition
Intuition and judgment
Creative
Behavioral
Avoidance
Peer acceptance
Feelings and instincts
Emotional

Table 1 & 2 Sources: Adapted from Rowe, A. J. and Boulgarides, J. D..  Managerial Decision Making. Upper Saddle River, NJ: Prentice Hall.,1994. Rpt in Marakas, George M.. Decision Support Systems. Upper Saddle River, NJ: Prentice Hall, 2003. 43-44.


Table 1
groups the types in two dimensions. The first dimension is Complexity versus Structure. This dimension can be thought of as where the person leans internally in processing information and making decisions. For example, whether a person is comfortable with ambiguity or not. The second dimension is Task/Technical versus People/Social. This dimension is more of the external expression of decision making. For example, whether a person chooses to create tasks and procedures versus socializing ideas as a path to decisions.

Table 2 further analyzes the types by Behavior under Stress, Motivation, Problem-solving Strategy, and Nature of Thought. The stress and motivation columns are particularly interesting. If there is a mismatch in the design of a DSS to the behavioral type then we can infer that some of the down-sides of the particular decision-making style will magnify. For example, the Analytical type would most likely prefer a flexible system where they have broad access to data and can create their own reports. They may even prefer to write their own procedures. So this system should have a flexible report-writing and output mechanisms. Conversely, a Directive type may prefer a dashboard with Key Performance Indicators, Balanced Scorecard, and summary data in order to scan the environment and make quick decisions.

With preliminary understanding of DSS and behavioral types in mind, we can expand these ideas to our working relationships with each other.  Managers, subordinates, and the organization could use a similar framework in helping people work constructively with each other.  Each person can consider how the other works best, and value what each person emphasizes in his or her decision-making process. An Analytical, for example, should filter and structure information for the Directive, rather than dumping massive amounts of information on them. Conversely, a Directive should give the Analytical space and resources to research rather than overly imposing their personal preferences for structure limitations and speed.


The types can flow quite well together and make each other more effective. A Directive can help guide the Analytical and Conceptual who might take too long analyzing or analyzing too broadly. Conversely, an Analytical can help a Directive fact-check and validate ideas because the Analytical will dive into the details. A Conceptual can provide the broad and inspired outlook from synthesizing a lot of information. The Analytical can work out the feasibility and steps. Directives can push things forward. The Behavioral can provide the reliable supportive environment.

Given cognitive biases, there can be a tendency to focus on the weaknesses of a person’s decision-making style in an attempt to change the behavioral type to what they are not. For example, incorrectly thinking that a Directive should analyze more volumes of data; the Behavioral should be more assertive; the Analytical should take less time researching; the Conceptual should spend their time doing tasks, etc. Rather than successfully changing the person’s style, these misguided efforts could result in de-motivating and magnifying the stress responses of the type. By respecting and working with the person’s strengths, the best can be brought out.

The interplay and conflict between the types can constructively balance effectiveness and efficiency of decision-making, but at worse, whoever has the most power, can tip the balance which can put the outcome of decisions at greater risk as well as put a wrinkle in relationships for future projects.



References:

Marakas, George M.. Decision Support Systems. Upper Saddle River, NJ: Prentice Hall, 2003.


Using DAAPI with ASP.Net

Within Microsoft, DAAPI is a great solution to that nagging problem of protecting a key or passphrase. It is fairly straightforward, but is slightly tricky when used with ASP.Net. Builder.au provides a good overview for how to get it to work, although there might be extra, yet remote, security considerations loading unencrypted keys in the application pool.

.Net Secure Code Snippets

Here is a nice page of links to .Net secure code snippets.

http://channel9.msdn.com/wiki/default.aspx/SecurityWiki.CodeExamples

Up a level, the Microsoft Security Wiki homepage is a great place to learn. This resource would have saved me a lot of time learning some important security concepts and practices in .Net.

Julie Lerman in the Geekette photo

This is a treat. I received an email from Julie that she is going to use my photo of her on the Vermont .Net User Group site.

Afghan Stories: Giving Women a Voice

Tuesday, January 15th, a friend and I attended Paula Lerner’s multimedia presentation “Afghan Stories: Giving Women a Voice” hosted at the Belmont Gallery of Art. This was an inspiring and eye-opening event. Paula’s photographs taken in Kabul and Kandahar show a side of Afghan life that is not frequently shown in the mass media. Paula would point out that the media has largely ignored pictures and stories that show more positive developments in the country. The photographs were intimate moments, colorful and expressive in composition, and showcasing a range of everyday life.

The multimedia presentation featured in depth stories about women, many who are running their own businesses. One woman opened the first fitness gym for women in the more liberal city of Kabul with the mission to help women feel good about themselves. Special guest Rangina Hamidi shared her stories and insights on the experiences, hopes, and challenges of Afghan women. She started her work through Bpeace and helped create Kandahar Treasure, a socially conscious business project that brings materials to women’s homes so they can be paid to create fine embroidery work. Most women outside of Kabul cannot work outside of the home and must be accompanied by a man, so for many this is their first opportunity to earn an income. This project is successfully working inside the constraints of the strict, traditional culture. One can imagine that these opportunities for women will spark economic, emotional, and creative empowerment that may lead to more freedom and opportunity for women over time. Rangina was particularly inspired by women who had led a peace prayer in Kandahar. Her blog post best captures the moment:

Today, for the first time in Kandahar’s history the women of Kandahar organized to hold a special peace prayer at the sacred Shrine of the Prophet (Kherqa Sharif) in Kandahar.

This program was organized by ordinary mothers, sisters and daughters of men who have lost their lives in these unjust times - they have realized that politics, international policies and the current leaders of the country have not been able to calm the situation in their country. They have learned to turn to God to help….I am proud of all the women here because inspite of the situation on the ground the women still gathered to show their solidarity and sisterhood in peace.

An audience member asked Rangina about safety given that her advocating for women, as well as her work and travel in the country may be frowned upon. She stated that she is mindful and careful, but made a decision to not be afraid. I was truly inspired by Rangina to overcome fears and doubts.

Debug HTTP and SOAP traffic with Fiddler

Fiddler categorizes and formats HTTP and XML SOAP traffic, making it easier to find issues.  However, you cannot change values in the tools to test changes. You have to do this from the source.

Tcpmon is also quite useful and speedy to monitor packets where Fiddler may not seem as suited for the job. Additionally, you can tweak source packets such a soap constructs directly and resend.

Another HTTP monitoring tool http://www.xk72.com/charles/

IE Developer Toolbar

Want a way to make your web page design and debugging work a bit more productive and easy? One of the coolest tools I saw at Russ’ Toolshed was the IE Developer Toolbar. You can do all of the things listed below by interacting with your web page while it’s loaded in IE, rather than tweaking code and reloading over and over. Someone commented that it looks better than Firebug.

From the MSDN site:

The Internet Explorer Developer Toolbar provides several features for exploring and understanding Web pages. These features enable you to:

  • Explore and modify the document object model (DOM) of a Web page.
  • Locate and select specific elements on a Web page through a variety of techniques.
  • Selectively disable Internet Explorer settings.
  • View HTML object class names, ID’s, and details such as link paths, tab index values, and access keys.
  • Outline tables, table cells, images, or selected tags.
  • Validate HTML, CSS, WAI, and RSS web feed links.
  • Display image dimensions, file sizes, path information, and alternate (ALT) text.
  • Immediately resize the browser window to a new resolution.
  • Selectively clear the browser cache and saved cookies. Choose from all objects or those associated with a given domain.
  • Display a fully featured design ruler to help accurately align and measure objects on your pages.
  • Find the style rules used to set specific style values on an element.
  • View the formatted and syntax colored source of HTML and CSS.

The Developer Toolbar can be pinned to the Internet Explorer browser window or floated separately.

Goodies for Note-taking and Brainstorming

Google Notebook makes it easy to collect research on the web. You can r-click on any page, image, or text fragment and add it to a notebook. You can also add your own comments and do categorizing, text formatting, and highlighting.With an appetite for using Google Notebook in mind, you can use any iGoogle note gadget to quickly jot ideas and tasks into your home page and then paste into a notebook as needed. Note gadgets are nifty during meetings when you don’t have the time (or presence of mind) to find the note taking tool you’d normally use. Just click on the home page and go.

Google Notebook is a collaborative tool, so you can keep each notebook private, shared, or published as a public web page. To add your own collaborative diagrams and pictures, you could use Gliffy or Best4c and Flickr or Picassa. Just publish the images, r-click and then add them to a notebook. Welcome to brainstorming mecca.