使用WebFaultException处理WCF服务rest错误
我需要处理WCF服务应用程序中的异常。 但是在windows应用程序中,我无法获取错误消息。它只显示为错误请求 在WCF服务中,抛出以下异常使用WebFaultException处理WCF服务rest错误,wcf,exception,bad-request,Wcf,Exception,Bad Request,我需要处理WCF服务应用程序中的异常。 但是在windows应用程序中,我无法获取错误消息。它只显示为错误请求 在WCF服务中,抛出以下异常 throw new WebFaultException<string>(string.Format("Invalid Client ID.", clientID), HttpStatusCode.BadRequest); 在windows应用程序客户端中,您必须捕获异常并获取错误的详细信息 try { client.YourSer
throw new WebFaultException<string>(string.Format("Invalid Client ID.", clientID), HttpStatusCode.BadRequest);
在windows应用程序客户端中,您必须捕获异常并获取错误的详细信息
try
{
client.YourServiceMethod();
}
catch (FaultException<string> ex)
{
MessageFault messageFault = ex.CreateMessageFault();
Console.WriteLine(messageFault.GetDetail<string>());
}