我正在从几天的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; }但是,如果Service中的身份验证失败,则Reply.IsFault仅返回false。 任何人都可以向我解释什么是回复。这个错误以及它对我有用的程度如何?
I am working on WCF Services from Couple of Days. I had a written a service with an Exception as
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; }After this i am handling the exceptions in client side in a Messgae Inspector as
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); } } }I am handling my Client Side Code as
try { objVendorServiceClient.Login(txtuserName.Text.Trim(), txtAccessCode.Text.Trim()); } catch (FaultException ex) { lblAuthenticationMessage.Text = ex.Message; throw ex; }But when ever the authentication fails in Service, the Reply.IsFault is returning false only. could any one explain me what is reply.Isfault and how exactly it is useful to me?
最满意答案
Message.IsFault属性 :
获取一个值,该值指示此消息是否生成任何SOAP错误。
你说:
当Service中的身份验证失败时,Reply.IsFault返回false
那是因为你自己捕获了错误,记录它,然后返回一个空字符串。 您必须抛出FaultException,以便WCF捕获它并从中创建SOAP错误。
Message.IsFault Property:
Gets a value that indicates whether this message generates any SOAP faults.
You say:
when ever the authentication fails in Service, the Reply.IsFault is returning false
That is because you catch the fault yourself, log it, and then return an empty string. You'll have to throw the FaultException in order for WCF to catch it and create a SOAP fault from it.
更多推荐
发布评论