2010-12-20 132 views
0

我正在將WPF應用程序遷移到Silverlight。我的WPF應用程序使用BackgroundWorker訪問Web服務。如果有任何錯誤,而訪問Web服務,我在我的回調得到了廣泛的錯誤信息,例如WCF客戶端返回錯誤「遠程服務器返回錯誤:NotFound。」

There was no endpoint listening at http://localhost:8080/services/registration 
that could accept the message. This is often caused by an incorrect address or 
SOAP action. See InnerException, if present, for more details. 

在我的Silverlight應用程序,我異步訪問同一個web服務,現在我的錯誤消息是不是很有用的,例如:

The remote server returned an error: NotFound. 

Web服務沒有改變 - 我可以看到來自Fiddler服務器上的故障。所以問題是如何在Silverlight客戶端上獲得更詳細的錯誤消息。

我的Silverlight應用程序的回調看起來像這樣(我訪問來自e.Error.Message錯誤消息):

private void AuthenticateUserCallback(object sender, AuthenticateUserCompletedEventArgs e) 
{ 
    if (e.Error != null) 
    { 
     this.StatusMessage = e.Error.Message; 
    } 

    ... 
} 

回答

0

這是瀏覽器堆棧的限制,由於其SL無法訪問完整的異常消息。查看MSDN文章here 該方法將異常封裝爲有意義的錯誤(這意味着客戶端將始終獲得HTTP OK 200)並在客戶端執行自定義異常處理。

+0

謝謝Chandermani。非常有用的鏈接。 – Naresh 2010-12-20 22:28:38

相關問題