2012-02-24 8 views
0

WebClientを呼び出して文字列を返すプロキシとしてWCFサービスがあります。 WebClientは、ユーザー名とパスワードがhttps経由で送信されるTokenサービスを照会しています。 UsernameとPasswordが正しい場合、サービスはうまく動作しますが、ユーザー名とパスワードが無効な場合、WebClientは、以下のコードで予想され処理される例外(403 Forbidden)をスローします。しかしWCFサービスは、タイムアウトするまでハングアップして、なぜそれがわからないのか把握します。WebClientが例外を返す場合、WCFサービスがタイムアウトします。

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 

WCFリファレンスファイルをデバッグイムは私に自動取り込まクライアント側メソッドで例外を示していたとき、私はまたことを追加する必要があります。

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 

私の事はある、私は、WCFサービスで例外を処理し、カスタムクラス内で例外を返すことで、私は問題なしとランタイムユーザーまでの例外をプッシュすることができていると考えていることです。ここで例外がキャッチされたクライアント側です:

System.ServiceModel.CommunicationException was unhandled by user code 

メッセージ=リモートサーバーがエラーを返しました:NotFound。 のStackTrace:System.ServiceModel.AsyncResult.End [TAsyncResult](たIAsyncResult結果)で System.ServiceModel.Channels.ServiceChannel.EndCallでSystem.ServiceModel.ClientBase 1.ChannelBaseで (文字列アクションは、[]アウト、たIAsyncResult結果オブジェクト) MatrixWebMap.AuthServiceRef.AuthServiceClientでMatrixWebMap.AuthServiceRef.AuthServiceClient.AuthServiceRef_AuthService_EndGetToken(たIAsyncResult結果) でMatrixWebMap.AuthServiceRef.AuthServiceClient.AuthServiceClientChannel.EndGetToken(たIAsyncResult結果) で1.EndInvoke(文字列methodNameの、オブジェクト[]引数、たIAsyncResult結果) .OnEndGetToken(IAsyncResult result) at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result) Inne rException:System.Net.WebException メッセージ=リモートサーバーがエラーを返しました:NotFound。 のStackTrace:System.Net.Browser.AsyncHelper.BeginOnUIで (SendOrPostCallback beginMethod、オブジェクト状態) System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(たIAsyncResult asyncResult) でSystem.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequestました。 CompleteGetResponse(IAsyncResult result) InnerException:System.Net.WebException メッセージ=リモートサーバーがエラーを返しました: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(sendStateオブジェクト) のInnerExceptionは:

+0

おそらく、あなたはTokenServiceを処分するからでしょうか? –

+0

disposeメソッドをコメントアウトすると何も変更されませんでした。 – BrokenRobot

+0

例外は何ですか? –

答えて

0

だから、私はTokenResultクラスに例外を追加し、それを返すときに私が集まる何から、WCF応答は、例外プロパティに問題がありました。回避策は、応答の前に例外を処理し、TokenExceptionを結果を保持する前に作成される文字列にすることでした。

したがって、 '403 Forbidden' Web例外の場合、私は単純に文字列を作成して返しました。あなたが入力した情報は私たちのレコードと一致しません。もう一度やり直してください。 "汚れた作業の種類ですが、ここで何をしようとしているのかに完全に適しています。

  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 
+0

私は、WCFの応答がクライアントにXML形式で返され、例外クラスとして返されるため、例外が未手続きの例外として受け取られることが考えられます。サーバーサイドを処理して文字列を返すことは、おそらくこれを行う良い方法です。 – BrokenRobot

関連する問題