我在WCF服务上工作了几天。我有一个写好的服务,但有一个异常
public String Login(string Vendorname, string VendorAccessCode)
{
try
{
if()
{
}
else
{
UserIdentityToken = string.Empty;
this.ErrorMessage = "Authentication failed. Please contact administrator";
throw new FaultException(this.ErrorMessage);
}
}
catch (FaultException ex)
{
logger.Error(ex.Message);
}
catch (Exception ex)
{
logger.Error(ex.Message);
}
return UserIdentityToken;
}之后,我将在Messgae Inspector中处理客户端的异常,如下所示
public class MessageInspector : IClientMessageInspector
{
public void AfterReceiveReply(ref Message reply, object correlationState)
{
if (reply.IsFault)
{
MessageFault fault = MessageFault.CreateFault(new FaultCode("Receiver"), new FaultReason(reply.ToString()));
throw new FaultException(fault);
}
}
}我将我的客户端代码处理为
try
{ objVendorServiceClient.Login(txtuserName.Text.Trim(),
txtAccessCode.Text.Trim());
}
catch (FaultException ex)
{
lblAuthenticationMessage.Text = ex.Message;
throw ex;
}但是,当身份验证在服务中失败时,Reply.IsFault仅返回false。谁能给我解释一下什么是reply.Isfault,它到底对我有什么用处?
发布于 2012-12-10 17:54:14
:
获取一个值,该值指示此消息是否生成任何SOAP错误。
你可以说:
每当身份验证在服务中失败时,Reply.IsFault将返回false
这是因为您自己捕获错误,记录它,然后返回一个空字符串。您必须抛出FaultException,以便WCF捕获它并从中创建SOAP错误。
https://stackoverflow.com/questions/13798474
复制相似问题