[英]Exception unhandled by user code C#
I have WCF service in which I want raise an Exception, when I am raising an exception then I getting Error Exception unhandled by user code . 我有WCF服务,我想在其中引发异常,当我引发异常时,我得到用户代码未处理的 Error Exception 。 Please someone can figure this Issue.
请有人可以解决此问题。 My Interface is as follows:
我的界面如下:
[ServiceContract]
public interface IADSICAuthentication
{
[WebInvoke(Method = "POST", UriTemplate = "Login", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
Response LoginClient(Credentials credentials);
}
and my LoginCLient Method defines below 和我的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
}
}
You can use FaultException. 您可以使用FaultException。 FaultException can throw a specific exception, so you will be able to identify the type using catch.
FaultException可以引发特定的异常,因此您可以使用catch来识别类型。
Here I gave an similar answer with an example: Proper way to throw exception over WCF 在这里,我以一个示例给出了类似的答案: 在WCF上引发异常的正确方法
You should use FaultException<T>
and mark up your ServiceContract
class to include which types are expected. 您应该使用
FaultException<T>
并标记ServiceContract
类以包含期望的类型。
Details on how to use it are available at MSDN - FaultException MSDN上提供了有关如何使用它的详细信息-FaultException
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.