eConnect: The creator of this fault did not specify a Reason

eConnect WCF exception handling

For this example a WCF service reference to the server endpoint running the GP2010 eConnect integration service as a reference named “GPeConnect” is used.

If an exception were to occur from eConnect on say the CreateEnity mehods, and the exception examined as type system.exception, then the following message is found from ex.message,

System.ServiceModel.FaultException: The creator of this fault did not specify a Reason

To retrieve the error message from econnect that we are interested in, use the System.ServiceModel.FaultException class as shown below. By accessing the Detail.Message property, it is possible to get message of interest.

Example of error handling WCF eConnect using FaultException

With the example that follows, ex.Detail.Message will contain a string from eConnect with a good description of what the issue was.

' Do not use using block with WCF client http://msdn.microsoft.com/en-us/library/aa355056.aspx 
Dim eConnectWCFServiceInstance = New GPeConnect.eConnectClient
Try
    ResultFromeConnect =
        eConnectWCFServiceInstance.CreateEntity(connectionString, xmlDocument.OuterXml)
    eConnectWCFServiceInstance.Close()
Catch ex As System.ServiceModel.FaultException(Of GPeConnect.eConnectFault)
    ErrorText = ex.Detail.Message
    eConnectWCFServiceInstance.Close()
Catch ex As System.ServiceModel.FaultException(Of GPeConnect.eConnectSqlFault)
    ErrorText = ex.Detail.Message
    eConnectWCFServiceInstance.Close()
Catch ex As ServiceModel.CommunicationException
    eConnectWCFServiceInstance.Abort()
    Throw
Catch ex As TimeoutException
    eConnectWCFServiceInstance.Abort()
    Throw
Catch ex As Exception
    eConnectWCFServiceInstance.Abort()
    Throw
Finally
    eConnectWCFServiceInstance.Dispose()
End Try' Do not use using block with WCF client http://msdn.microsoft.com/en-us/library/aa355056.aspx 
Dim eConnectWCFServiceInstance = New GPeConnect.eConnectClient
Try
    ResultFromeConnect =
        eConnectWCFServiceInstance.CreateEntity(connectionString, xmlDocument.OuterXml)
    eConnectWCFServiceInstance.Close()
Catch ex As System.ServiceModel.FaultException(Of GPeConnect.eConnectFault)
    ErrorText = ex.Detail.Message
    eConnectWCFServiceInstance.Close()
Catch ex As System.ServiceModel.FaultException(Of GPeConnect.eConnectSqlFault)
    ErrorText = ex.Detail.Message
    eConnectWCFServiceInstance.Close()
Catch ex As ServiceModel.CommunicationException
    eConnectWCFServiceInstance.Abort()
    Throw
Catch ex As TimeoutException
    eConnectWCFServiceInstance.Abort()
    Throw
Catch ex As Exception
    eConnectWCFServiceInstance.Abort()
    Throw
Finally
    eConnectWCFServiceInstance.Dispose()
End Try

image