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.ChannelBase
1.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: