Note that there are some explanatory texts on larger screens.

plurals
  1. POUse delegates to Convert wcf service return object
    text
    copied!<p>The function below takes any wcf service method and invokes it.</p> <pre><code>Private Function ServiceCall(ByVal functionToCall As ServiceDelegate(Of IEmpService)) As Object Dim channel As New ChannelFactory(Of IEmpService)(_endPoint) Dim serv As IEmpService Dim result As Object = Nothing Dim mostRecentExp As Exception = Nothing Dim noOfRetries As Integer = My.Settings.NoOfRetries Dim initialDelay As Integer = My.Settings.InitialDelayInMS serv = channel.CreateChannel() For i As Integer = 0 To noOfRetries Try result = functionToCall.Invoke(serv) mostRecentExp = Nothing Exit For Catch cte As ChannelTerminatedException mostRecentExp = cte Thread.Sleep(initialDelay * (i)) Catch enf As EndpointNotFoundException mostRecentExp = enf Thread.Sleep(initialDelay * (i)) Catch stb As ServerTooBusyException mostRecentExp = stb Thread.Sleep(initialDelay * (i)) Catch vf As FaultException(Of ValidationFault) 'no retry Catch exp As Exception 'any other exception mostRecentExp = exp Thread.Sleep(initialDelay * (i)) Finally If channel.State = CommunicationState.Faulted Then channel.Abort() Else channel.Close() End If End Try Next If mostRecentExp IsNot Nothing Then Throw New ServiceExceptions(String.Format("Call to method {0} failed", functionToCall.ToString()), mostRecentExp.InnerException) End If Return result End Function </code></pre> <p>I determine whether a retry is required or not depending on the type of exception I get, which all are fine. the issue I'm facing is <code>result = functionToCall.Invoke(serv)</code> where the result is an object and it can contain a custom error object, and in that case it wont be an exception. to get to the error I can do something similar to: <code>If TypeOf result Is SaveAddressResponse Then ElseIf TypeOf result Is SaveDetailResponse Then End If</code> which looks messy so like to know If I could use delegate to get errors from the <code>return</code> object?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload