Avatar of P_Ramprathap
P_RamprathapFlag for India

asked on 

Fault Exception Handling in WCF

While throwing exception from my WCF service . iam getting the following error message

FaultException `1 was un handled by user code

 

System.ServiceModel.FaultException`1 was unhandled by user code

  Message="Oracle.DataAccess.Client.OracleException ORA-20003: EmpNo (Exxxx) Dosent Exists Or Dont have sufficent previlage\nORA-06512: at \"PKG\", line 38\nORA-06512: at \"PKG\", line 39\nORA-06512: at line 1    at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure)\r\n   at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src)\r\n   at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)\r\n   at Oracle.DataAccess.Client.OracleDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)\r\n   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)\r\n   at SQLManager.Oracle.DataAccess.ExecuteDataSet(ExecuteDataSetParameterMessage parameter) ..........

 
i have enclosed the code below

private void ProcessException(string message, Exception innerException)
{
SqlManagerException ex = new SqlManagerException(message, innerException);
 
            
 
if (Messages != null)
{
  for (int i = 0; i < messages.Count; i++)
  {
       ex.InfoMessages.Add(messages[i]);
     }
  }
  SqlManagerExceptionMessage exm = new SqlManagerExceptionMessage(ex);
 
  faultReason = new FaultReasonText(exm.Message.InnerException.ToString());
 
  exm.Message = ex;
  throw new FaultException<SqlManagerExceptionMessage>(new SqlManagerExceptionMessage(exm.Message), faultReason.Text);
 
}
And the SqlManagerExceptionMessage .cs is 
 
using System.ServiceModel;
using System.Runtime.Serialization;
 
namespace SQLManager
{
 
    [DataContractAttribute]
    public class SqlManagerExceptionMessage
    {
        [DataMember]
        private SqlManagerException report;
 
 
        public SqlManagerExceptionMessage(SqlManagerException message)
        {
            this.report = message;
        }
 
        [DataMemberAttribute]
        public SqlManagerException Message
        {
           get { return this.report; }
            set { this.report = value; }
        }
        
 
        //public SqlManagerException Exception
        //{
        //    get { return exception; }
        //    set { exception = value; }
        //}
    }
}
 
 
SqlManagerException .cs is 
 
 [Serializable()]
	public class SqlManagerException : ApplicationException,ISerializable
	{
        private SqlManagerInfoMessageList messages;
 
        public SqlManagerException() : base() { }
 
        public SqlManagerException(string message) : base(message) { }
 
        public SqlManagerException(string message,
            Exception innerException)
            : base(message, innerException) { }
                      
        public SqlManagerException(SerializationInfo info, StreamingContext context) : base(info, context) 
        {             
            messages = (SqlManagerInfoMessageList)info.GetValue("messages", typeof(SqlManagerInfoMessageList));            
        }
 
 
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("messages", messages, typeof(SqlManagerInfoMessageList));
            base.GetObjectData(info, context);
        }
		
        /// <summary>A collection of information messages retrieved from connection.</summary>
        public SqlManagerInfoMessageList InfoMessages
        {
            get
            {
                if (messages == null)
                {
                    messages = new SqlManagerInfoMessageList();
                }
			    
                return messages;
            }
 
            set
            {
                messages = value;
            }
        }
        
		
    }
}

Open in new window

.NET Programming

Avatar of undefined
Last Comment
ororiole
Avatar of ororiole
ororiole
Flag of United States of America image

Why do you think it is happening while you are throwing an exception? You are getting an Oracle server exception:
Oracle.DataAccess.Client.OracleException ORA-20003: EmpNo (Exxxx) Dosent Exists Or Dont have sufficent previlage\nORA-06512: at \"PKG\", line 38

could it be occuring somewhere else in the code? The only place in the code you provided where you could be accessing an oracle database is in:
public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("messages", messages, typeof(SqlManagerInfoMessageList));
            base.GetObjectData(info, context);
        }
where you serialize your data. You probably in fact are not accessing the database correctly. Set a breakpoint at the beginning of GetObjectData and step and see thats true. Then find out what you need to do to get access to the database.
Avatar of P_Ramprathap
P_Ramprathap
Flag of India image

ASKER

The problem is not there , the execption thown is correct , i need to propagate this message to the client from which iam calling this service . So the Client will indicate the Empno entered by the user is invalid.
I have enclosed the screenshoot of the error message iam getting in the client while iam propagting the exception from service to cleint.
 

exception.JPG
Avatar of ororiole
ororiole
Flag of United States of America image

I dont see how that error tells us anything specific. Your OperationContract that throws the fault must also be marked with the FaultContract. So whatever method the client calls that eventually calls your ProcessException method should be marked with [OperationContract] and [FaultContract(typeof(SqlManagerExceptionMessage)]

And are you trying to catch the strongly typed exception in the client?
try{
  //call a service opertaion
}
catch (FaultException<SqlManagerExceptionMessage> stfex)
{
  //handle this stongly typed fault. See the Details property
}
catch (FaultException fex)
{
  //process other WCF exceptions
}
catch (Exception ex)
{
  everything else
}

Open in new window

Avatar of P_Ramprathap
P_Ramprathap
Flag of India image

ASKER

Ya , we have tried before , i feel that there is some basic problem in config settings which is restricting the exception to refelect in client side , iam not sure , is there any specific settings that i need to do for exception handling
<system.serviceModel>
	    <bindings>
          <customBinding>
              <binding name="SQLManager">
                <mtomMessageEncoding></mtomMessageEncoding>
                 <reliableSession  flowControlEnabled ="true" ordered ="true" />
                 <httpTransport useDefaultWebProxy="true" />
              </binding>
          </customBinding>
      </bindings>
		  <services>
          <service behaviorConfiguration="SQLManager.Oracle.DataAccessBehavior"
                   name="SQLManager.Oracle.DataAccess">
              <endpoint address="http://localhost/SQLManager/Oracle/DataAccess.svc" behaviorConfiguration="SQLManagerBehavior"
                        binding="customBinding" bindingConfiguration="SQLManager" name="SQLManager"
                        contract="SQLManager.Oracle.IDataAccess" />
              <endpoint address="mex"
                        binding="mexHttpBinding"
                      contract="IMetadataExchange" />
             
               <host>
                 <baseAddresses>
                     <add baseAddress="http://localhost/SQLManager/Oracle" />
                 </baseAddresses>
              </host>
          </service>
      </services>
		  <behaviors>
			    <serviceBehaviors>
				      <behavior name="SQLManager.Oracle.DataAccessBehavior">
					        <serviceMetadata httpGetEnabled="true"  />
					        <serviceDebug includeExceptionDetailInFaults="true"/>
                <dataContractSerializer maxItemsInObjectGraph="150000" />
				      </behavior> 
			    </serviceBehaviors>
        <endpointBehaviors >
          <behavior name="SQLManagerBehavior">
            <dataContractSerializer maxItemsInObjectGraph="150000" />
          </behavior>
        </endpointBehaviors>
		  </behaviors>
      <diagnostics>
           <messageLogging logEntireMessage="true" logMalformedMessages="true"
                logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
      </diagnostics>
  </system.serviceModel>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ororiole
ororiole
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo