• Home
  • About
  • BestBloggingIdeas
  • DotNetLearningSource
  • FORUM
  • Joblinks
  • Latest News
  • Policy
  • POSTS
  • SimplySqlServer.Com && SimplyAspDotNet.Com
  • Sitemap

Join Ours Forum

Asp.Net,C#,Ajax,Sql server,silverlight,Javascript codes exambles articles,Programming exambles

RSS Feed
  • Bounty Huge Roll [Amazon Frustration-Free Packaging]
  • XML Introduction to XML VHS Video Training, 1 hr., 32 minutes.
  • The Basic Overview of Windows Mobile Development Asp.Net C#
  • Overview of Sql server extended properties Asp.Net C#
  • How to Use Sql Server Extended properties using visual studio Asp.Net C#
  • Adobe Dreamweaver Templates Accelerate Web Development
  • Top Tips for Web Design Projects
  • How to Achieve a Good Web Design Structure
  • To Use Or Not To Use Website Templates
  • Five Tips to a Successful Website
  • Top 10 Articles,


    Silverlight Datagrid Select Update Delete Insert Asp.Net C#

    Differences Similarities Benefits Between Typed Datasets and Untyped Datasets asp.net c#

    Linq to Sql Introduction Entities Ado.Net C# SqlClasses Attributes Linq Mapping

    Linq Programming/How Linq Works?/Linq Implementation In Asp.Net C# Ado.Net

    Performing Developing Using Investigating Asp.Net 2.0 Ajax Application Development Asp.Net C#

    Hosting/Install Wcf Services in a Windows Service Asp.Net C#

    Connecting Silverlight to Wcf Asp.Net C#

    Silverlight Data Grid Data Binding WCF Asp.Net C#

    Invoking/Accessing/Calling WCF Service Without Adding/Creating Proxy/Reference Asp.Net C#

    Performing Doing Creating Insert Update Delete sql data Using Linq Database Asp.Net C#

    Exception Handling WCF Programming/Services Fault Exception Asp.Net c#

    Posted by on August 6, 2010 Leave a comment (8) Go to comments

    Introduction:
    In this article,i am going to explain about how to handling exceptions in wcf services using fault exception.

    Main:

    Fault Handling in WCF:
    The default behavior for WCF is not to return that exception to the client unless it is thrown as a FaultException
    (or inherited subtype) or if a FaultContract is implemented.

    See this below simple examble,

    Service Code:

    using System.Data;
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.ServiceModel;
    using System.Runtime.Serialization;
     
    using System.Threading;
     
    using System.Security;
    using System.Security.Permissions;
    using System.Security.Principal;
     
    namespace Products
    {
        // Simplified service contract
        [ServiceContract(Namespace = "http://NetProgrammingHelp.com/2006/09/30", Name = "SimpleProductsService")]
        public interface ISimpleProductsService
        {
            [OperationContract(Name = "ListProducts")]
            List<string> ListProducts();
        }
     
     
        // WCF service class that implements the service contract
        public class ProductsServiceImpl : ISimpleProductsService
        {
            public List<string> ListProducts()
            {
                // Read the configuration information for connecting to the NetPrgHlp database
                Database dbNetPrgHlp;
                try
                {
                    dbNetPrgHlp = DatabaseFactory.CreateDatabase("NetPrgHlpConnection");
                }
                catch (Exception e)
                {
                    throw new FaultException("Exception reading configuration information for the NetPrgHlp database: " + e.Message, new FaultCode("CreateDatabase"));
                }
     
                // Retrieve the details of all products by using a DataReader
                IDataReader productsReader;
                try
                {
                    string queryString = @"SELECT ProductNumber 
                                           FROM Production.Product";
                    productsReader = dbNetPrgHlp.ExecuteReader(CommandType.Text, queryString);
                }
                catch (Exception e)
                {
                    throw new FaultException("Exception querying the NetPrgHlp database: " + e.Message, new FaultCode("ExecuteReader"));
                }
     
                // Create and populate a list of products
                List<string> productsList = new List<string>();
                try
                {
     
                    while (productsReader.Read())
                    {
                        string productNumber = productsReader.GetString(0);
                        productsList.Add(productNumber);
                    }
                }
                catch (Exception e)
                {
                    throw new FaultException("Exception reading product numbers: " + e.Message, new FaultCode("Read/GetString"));
                }
     
                //Return the list of products
                return productsList;
            }
        }
    }

    Client Code:

    using System.ServiceModel;
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.ServiceModel.Channels;
     
    namespace ProductsClient
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Press ENTER when the service has started");
                Console.ReadLine();
     
                try
                {
                    // Create a default HTTP binding
                    BasicHttpBinding httpBinding = new BasicHttpBinding();
     
                    // Create an endpoint
                    EndpointAddress address = new EndpointAddress(
                        "http://localhost:8040/SimpleProductsService/SimpleProductsService.svc");
     
                    IChannelFactory<IRequestChannel> factory =
                        httpBinding.BuildChannelFactory<IRequestChannel>();
                    factory.Open();
     
                    IRequestChannel channel = factory.CreateChannel(address);
                    channel.Open();
     
                    Message request = Message.CreateMessage(MessageVersion.Soap11,
                        "http://NetPrgHlp.com/2006/09/30/SimpleProductsService/ListProducts");
     
                    Message reply = channel.Request(request);
                    Console.Out.WriteLine(reply);
     
                    request.Close();
                    reply.Close();
                    channel.Close();
                    factory.Close();
                }
     
                catch (Exception e)
                {
                    Console.WriteLine("Exception: {0}", e.Message);
                }
     
                Console.WriteLine("Press ENTER to finish");
                Console.ReadLine();
            }
        }
    }

    Conclusion:
    Hope this helps,
    Happy coding.

    WCF
    ← creating/first asp.net mvc web application c# asp.net model view pattern
    UI element property binding wpf dependency property asp.net c# →

    Learn Easily Using Video Tutorials


    How to choose the right Java IDE – explained Eclipse NetBeans BlueJ

    Developing/Creating/Performing/Configuring Java Applications Using Eclipse IDE

    Step By Step Guide for Download/Install Configure Eclipse IDE for Java

    Editing data with the GridView control Asp.Net C#

    Registering/Configuring Web Controls globally in web.config file asp.net c#

    Registering/Configuring Web Controls globally in web.config file asp.net c#

    Best way to prepare asp.net Interview - Success Stories

    Download Important Questions and PPT's:

    Sql Server Important Questions Online free download

    Dotnet Important Questions Online free download

    Exploring Linq to Sql Process Flow

    Learn how to perform silverlight programming

    Learn OOPs concepts in better and well manner

    Learn Ajax in better and well manner

    Leave a comment

    8 Comments.

    1. mass megawatts wind power inc. August 8, 2010 at 1:25 am

      I truly loved this brilliant article. Please continue this awesome work. Regards, Duyq.

    2. lawn cutting August 8, 2010 at 3:22 am

      Usually I do not post on blogs, but I would like to say that this article really forced me to do so! Thanks, really nice article.

    3. Visco Elastic Memory Foam Mattress Topper August 11, 2010 at 7:59 am

      I knew I had been correct. My friend and I placed a bet about which web site was superior. I thought your webpage was much better created, but she believed this post on trendy style ideas was much better. We rounded up 5 loved ones memebers who experienced not observed possibly web site earlier to to study them every more than. Majority chose your site. Thanks for maintaing a great website.

    4. Haraye August 13, 2010 at 2:07 pm

      Seriously you should retake 4th grade… your grammar is atrocious! My eyes hurt, thanks.

    5. Candance August 13, 2010 at 2:28 pm

      You are a very smart person! :)

    6. Clementine August 13, 2010 at 2:48 pm

      Great man, glad to see this post, and I find your blog is so comfortable for me, just bookmark it to my social media…Thanks for sharing.All of my friends will see this.

    7. cna training August 22, 2010 at 5:50 pm

      found your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later

    8. softincprism@gmail.com March 23, 2011 at 11:44 am

      Thanks for Providing such a valuable Information!

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    *

    *


    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    Enter your email address:

    Delivered by FeedBurner

    • Recent Posts

      • Bounty Huge Roll [Amazon Frustration-Free Packaging]
      • XML Introduction to XML VHS Video Training, 1 hr., 32 minutes.
      • The Basic Overview of Windows Mobile Development Asp.Net C#
      • Overview of Sql server extended properties Asp.Net C#
      • How to Use Sql Server Extended properties using visual studio Asp.Net C#
    • Search by Tags!

      Application AspNet Basic between Black Bluetooth Build Business Collection Consultants Design Development Downloading effective Excel Experts Generics Implement Installing Interview Logic Management Microsoft Minutes Object Outlook Professional Programmer Programming Project Projects Questions Ready Select Server Services Silverlight Source Strings Studio Through using Visual Website Wordpress
    • Archives

      • August 2011
      • June 2011
      • May 2011
      • April 2011
      • March 2011
      • February 2011
      • December 2010
      • November 2010
      • October 2010
      • September 2010
      • August 2010
      • July 2010
      • June 2010
      • May 2010
      • April 2010
      • March 2010
      • February 2010
      • January 2010
      • December 2009
      • November 2009
      • October 2009
      • September 2009

    Copyright © 2012 NetProgrammingHelp.com

    Δ Top