Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用WebFaultException处理WCF服务rest错误_Wcf_Exception_Bad Request - Fatal编程技术网

使用WebFaultException处理WCF服务rest错误

使用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

我需要处理WCF服务应用程序中的异常。 但是在windows应用程序中,我无法获取错误消息。它只显示为错误请求

在WCF服务中,抛出以下异常

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>());
}