Click here to Skip to main content
15,894,180 members
Articles / Web Development / ASP.NET

Handling SoapException Detail with a WCF Client from a Web Service

Rate me:
Please Sign up or sign in to vote.
5.00/5 (11 votes)
4 Nov 2009CPOL10 min read 106K   1.5K   25  
How to catch and handle ASMX based SOAP exceptions in a WCF client.
namespace SoapClientTest
{
	partial class Form1
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.buttonSimple = new System.Windows.Forms.Button();
			this.buttonMultiElement = new System.Windows.Forms.Button();
			this.buttonComplex = new System.Windows.Forms.Button();
			this.rtbMessage = new System.Windows.Forms.RichTextBox();
			this.buttonClose = new System.Windows.Forms.Button();
			this.useXML = new System.Windows.Forms.CheckBox();
			this.SuspendLayout();
			// 
			// buttonSimple
			// 
			this.buttonSimple.Location = new System.Drawing.Point(13, 13);
			this.buttonSimple.Name = "buttonSimple";
			this.buttonSimple.Size = new System.Drawing.Size(163, 23);
			this.buttonSimple.TabIndex = 0;
			this.buttonSimple.Text = "Simple Soap Exception";
			this.buttonSimple.UseVisualStyleBackColor = true;
			this.buttonSimple.Click += new System.EventHandler(this.buttonSimple_Click);
			// 
			// buttonMultiElement
			// 
			this.buttonMultiElement.Location = new System.Drawing.Point(12, 42);
			this.buttonMultiElement.Name = "buttonMultiElement";
			this.buttonMultiElement.Size = new System.Drawing.Size(163, 23);
			this.buttonMultiElement.TabIndex = 2;
			this.buttonMultiElement.Text = "Multiple Soap Elements";
			this.buttonMultiElement.UseVisualStyleBackColor = true;
			this.buttonMultiElement.Click += new System.EventHandler(this.buttonMultiElement_Click);
			// 
			// buttonComplex
			// 
			this.buttonComplex.Location = new System.Drawing.Point(12, 71);
			this.buttonComplex.Name = "buttonComplex";
			this.buttonComplex.Size = new System.Drawing.Size(163, 23);
			this.buttonComplex.TabIndex = 3;
			this.buttonComplex.Text = "Complex Soap Detail";
			this.buttonComplex.UseVisualStyleBackColor = true;
			this.buttonComplex.Click += new System.EventHandler(this.buttonComplex_Click);
			// 
			// rtbMessage
			// 
			this.rtbMessage.Location = new System.Drawing.Point(12, 101);
			this.rtbMessage.Name = "rtbMessage";
			this.rtbMessage.Size = new System.Drawing.Size(466, 149);
			this.rtbMessage.TabIndex = 3;
			this.rtbMessage.TabStop = false;
			this.rtbMessage.Text = "This application demonstrates the handling of Soap Exception thrown by the web se" +
				"rvice. WCF is not able to access complex XML data encoded in the detail without " +
				"properly encoding the XML data.";
			// 
			// buttonClose
			// 
			this.buttonClose.Location = new System.Drawing.Point(403, 13);
			this.buttonClose.Name = "buttonClose";
			this.buttonClose.Size = new System.Drawing.Size(75, 23);
			this.buttonClose.TabIndex = 4;
			this.buttonClose.Text = "Close";
			this.buttonClose.UseVisualStyleBackColor = true;
			this.buttonClose.Click += new System.EventHandler(this.buttonClose_Click);
			// 
			// useXML
			// 
			this.useXML.AutoSize = true;
			this.useXML.Location = new System.Drawing.Point(183, 18);
			this.useXML.Name = "useXML";
			this.useXML.Size = new System.Drawing.Size(97, 17);
			this.useXML.TabIndex = 1;
			this.useXML.Text = "Output as XML";
			this.useXML.UseVisualStyleBackColor = true;
			// 
			// Form1
			// 
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.ClientSize = new System.Drawing.Size(490, 262);
			this.Controls.Add(this.useXML);
			this.Controls.Add(this.buttonClose);
			this.Controls.Add(this.rtbMessage);
			this.Controls.Add(this.buttonComplex);
			this.Controls.Add(this.buttonMultiElement);
			this.Controls.Add(this.buttonSimple);
			this.Name = "Form1";
			this.Text = "SoapClientTest";
			this.ResumeLayout(false);
			this.PerformLayout();

		}

		#endregion

		private System.Windows.Forms.Button buttonSimple;
		private System.Windows.Forms.Button buttonMultiElement;
		private System.Windows.Forms.Button buttonComplex;
		private System.Windows.Forms.RichTextBox rtbMessage;
		private System.Windows.Forms.Button buttonClose;
		private System.Windows.Forms.CheckBox useXML;
	}
}

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 Code Project Open License (CPOL)


Written By
CEO Intact Partners Inc
United States United States
My company specializes Microsoft Windows Azure Cloud Computing in private and public sector consulting. We have a number of highly visible successful cloud projects including Florida Voter Registration System for the elections in 2012.
Intact develops not just the cloud solution, we develop your organization. We know that the leap to cloud is a jump that most are unable to make. At the same time the demands for mobile devices and applications drain all the energy. Intact has successfully helped large business and government over the hump. We can help you too.
Visit us at: http://www.itintact.com

View my bio on LinkedIn.com at www.linkedIn.com/in/laultman

Comments and Discussions