[英]Exception unhandled by user code C#
我有WCF服務,我想在其中引發異常,當我引發異常時,我得到用戶代碼未處理的 Error Exception 。 請有人可以解決此問題。 我的界面如下:
[ServiceContract]
public interface IADSICAuthentication
{
[WebInvoke(Method = "POST", UriTemplate = "Login", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
Response LoginClient(Credentials credentials);
}
和我的LoginCLient方法定義如下
public Response LoginClient(Credentials oCredentials)
{
try
{
if(oCredentials.PassWord == null)
{
//something
}
else
{
throw new Exception(string.Format("UnAuthorize User : 401"));
}
}
catch (Exception e)
{
throw; // I am getting Exception here Unhandled by user code
}
}
您可以使用FaultException。 FaultException可以引發特定的異常,因此您可以使用catch來識別類型。
在這里,我以一個示例給出了類似的答案: 在WCF上引發異常的正確方法
您應該使用FaultException<T>
並標記ServiceContract
類以包含期望的類型。
MSDN上提供了有關如何使用它的詳細信息-FaultException
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.