0
votes

I have a WCF Service as a proxy that calls a WebClient to return a string. The WebClient is querying a Token service where the user name and password is sent via https. The service works fine if the Username and Password is correct however if the username and password are invalid the WebClient throws an exception (403 Forbidden) which is expected and handled in the code below. however the WCF service then proceeds to hang until it times out which i cant figure out why.

Public Function GetToken(un As String, pw As String, ref As String) As TokenResult Implements IAGSAuthentication.GetToken

        Dim Token As String
        Dim TokenURL As String = String.Format("https://server/arcgisserver/tokens?request=getToken&username={0}&password={1}&timeout={2}", un, pw, Timeout)
        Dim tokenResult As TokenResult = New TokenResult
        If TokenService.IsBusy = False Then

            Try
                Token = TokenService.DownloadString(New Uri(TokenURL))
                tokenResult.Token = Token
                Return tokenResult
                Exit Function
            Catch ANEx As ArgumentNullException
                TokenService.Dispose()
                tokenResult.TokenException = ANEx
                Return tokenResult
                Exit Function
            Catch WEx As WebException
                TokenService.Dispose()
                tokenResult.TokenException = WEx
                Return tokenResult
                Exit Function
            Catch CEx As CommunicationException
                TokenService.Dispose()
                tokenResult.TokenException = CEx
                Return tokenResult
                Exit Function
            Catch Ex As Exception
                TokenService.Dispose()
                tokenResult.TokenException = Ex
                Return tokenResult
                Exit Function
            End Try

        End If
        Return tokenResult
    End Function

I should also add that when im debugging the WCF Reference file shows me an exception at a auto populated clientside method.

Public Function EndGetToken(ByVal result As System.IAsyncResult) As AuthServiceRef.TokenResult Implements AuthServiceRef.AuthService.EndGetToken
                Dim _args((0) - 1) As Object
                Dim _result As AuthServiceRef.TokenResult = CType(MyBase.EndInvoke("GetToken", _args, result),AuthServiceRef.TokenResult)
                Return _result
            End Function

I thing is is that I thought that by handling the exception in the WCF service and returning the exception inside the custom class that I could push the exception up to the user without and runtime issues. Here is the Exception caught client side:

System.ServiceModel.CommunicationException was unhandled by user code

Message=The remote server returned an error: NotFound. StackTrace: at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result) at System.ServiceModel.ClientBase1.ChannelBase1.EndInvoke(String methodName, Object[] args, IAsyncResult result) at MatrixWebMap.AuthServiceRef.AuthServiceClient.AuthServiceClientChannel.EndGetToken(IAsyncResult result) at MatrixWebMap.AuthServiceRef.AuthServiceClient.AuthServiceRef_AuthService_EndGetToken(IAsyncResult result) at MatrixWebMap.AuthServiceRef.AuthServiceClient.OnEndGetToken(IAsyncResult result) at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result) InnerException: System.Net.WebException Message=The remote server returned an error: NotFound. StackTrace: at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result) InnerException: System.Net.WebException Message=The remote server returned an error: NotFound. StackTrace: at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.BrowserHttpWebRequest.<>c_DisplayClassa.b_9(Object sendState) at System.Net.Browser.AsyncHelper.<>c_DisplayClass4.b_0(Object sendState) InnerException:

1
Maybe it's because you dispose the TokenService?John Saunders
Commenting out the dispose method didnt change anything.BrokenRobot
System.ServiceModel.CommunicationException was unhandled by user code Message=The remote server returned an error: NotFound. StackTrace: at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result) ..... the thing is it was handled in code, i am returning the exception in the custom class TokenResult so im not sure where the exception is coming fromBrokenRobot
So, I suggest you add this information to your question. It would seem your question now is "what's the story with this NotFound exception"John Saunders
Could it be that when the exception is thrown a listener for a exception flag or something of the sort, flags that the WCF service encountered one causing not to work properly. When i debug it, it seems to hang when the function that returns the result of finishes.BrokenRobot

1 Answers

0
votes

So, from what I gather when i add the exception to the TokenResult class and return it, the WCF response had a problem with the exception property. The work around was to deal with the exception before the response and make the TokenException a string that is created before returing the result.

So, for a '403 Forbidden' web exception i simply constructed a string and returned ""The information you have entered does not match our records. Please try again." Kind of a dirty work around but its perfectly appropriate for what im trying to do here.

            Try
                Token = TokenService.DownloadString(New Uri(TokenURL))
                tokenResult.Token = Token
                Return tokenResult
                Exit Function

            Catch ANEx As ArgumentNullException                
                tokenResult.TokenException = ANEx.Message
                Return tokenResult
                Exit Function

            Catch WEx As WebException                   
                If WEx.Status = WebExceptionStatus.ProtocolError Then
                    tokenResult.TokenException = "The information you have entered does not match our records. Please try again."
                Else
                    tokenResult.TokenException = WEx.Message
                End If
                Return tokenResult
                Exit Function

            Catch CEx As CommunicationException      
                tokenResult.TokenException = CEx.Message
                Return tokenResult
                Exit Function

            Catch Ex As Exception                    
                tokenResult.TokenException = Ex.Message
                Return tokenResult
                Exit Function
            End Try