Ok, so you have developed a nice WCF Service with proper implementation of custom fault exception handling, now you want to call this service in a web application or other client application and catch the fault exception in your client code. For simplicity I am using a web page, the following code is self explanatory.

  1: Protected Sub btnGetCustomers_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetCustomers.Click
  2: 
  3:         Using wcfSrv As CustomerWcfService.CustomerServiceClient = New CustomerWcfService.CustomerServiceClient("WSHttpBinding_ICustomerService")
  4:             Try
  5:                 Dim custArr() As CustomerWcfService.Customer
  6:                 custArr = wcfSrv.GetCustomers()
  7:                 For Each cust As CustomerWcfService.Customer In custArr
  8:                     Response.Write("ID: " & cust.ID.ToString & " Name: " & cust.Name & "<br/>")
  9:                 Next
 10:                 lblStatus.Text = "No of Customer Records found: " & custArr.Length.ToString
 11: 
 12:                 'Custom Fault Exception Response from Service
 13:             Catch ex As ServiceModel.FaultException(Of CustomerWcfService.ErrorResponse)
 14:                 lblStatus.Text = "Code:" & ex.Detail.Code.ToString() & " Messgage:" & ex.Detail.Message & " Details:" & ex.Detail.Details
 15:                 wcfSrv.Abort()
 16: 
 17:                 'General Fault Exception
 18:             Catch ex As ServiceModel.FaultException
 19:                 lblStatus.Text = ex.ToString()
 20:                 wcfSrv.Abort() 
 21: 
 22:                 'General Exception
 23:             Catch exp As System.Exception
 24:                 lblStatus.Text = "Error:" & exp.ToString()
 25:                 wcfSrv.Abort()
 26: 
 27:             Finally
 28:                 wcfSrv.Close()
 29:             End Try
 30: 
 31:         End Using
 32: 
 33:     End Sub
 34: 

Signature

Comments

11/23/2009 10:48:19 PM #

jameschowdare

hi viswa,

how to we implement wcf in 3 tier, and where do we implement it,

give a desription or give simple 3 method(each tier have implement one method)



thiswil help us/lot of learner/developers

jameschowdare India

3/27/2010 5:40:50 PM #

Christopher Livingstone

I have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favorites site list and will be checking back soon. Please check out my site as well and let me know what you think.

Christopher Livingstone United States

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



About Me

Me Hello,my name is Vishwa Mohan Kumar.
I am a Software Architect. This blog is result of my experiments.

Flickr Photos

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

Recent Comments

Comment RSS

Live Traffic Feed