本文介绍了返回 WCF 自定义错误异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从 wcf 服务返回自定义故障异常时遇到了一些麻烦.与 wcf 服务对话的客户端应用程序得到 – 合同不匹配错误.这是我在服务中定义的错误合同:

I am having bit of trouble returning custom fault exception from wcf service. The client application talking to wcf service gets – contract mismatch error.Here is my fault contract defined in the service:

public partial class Fault
{
    string codeField;
    string messageField;
    string detailsField;
}

在服务中出错时,我正在创建自定义错误异常,如下所示:

On error in the service I am creating custom fault exception as following:

public void ProvideFault(Exception exception, MessageVersion version, ref Message       refMessage)
{
      mynamespace.Fault customFault = new mynamespace.Fault()
      {
           code = "Service Error",
           message = "Error Message",
           details = "Error Message"
      };

      FaultException<mynamespace.Fault> faultexception = new   FaultException<mynamespace.Fault>( customFault );

      MessageFault messageFault = faultexception.CreateMessageFault();

      refMessage = Message.CreateMessage( version, messageFault, faultNamespace );
}

此代码导致客户端中的合同不匹配错误.任何人都可以帮我找出问题所在吗?

This code causes contract mismatch error in client. Can anyone please help me finding what is wrong?

推荐答案

创建自定义故障合约的步骤

Steps to create a custom fault contract

http://bloggingabout.net/博客/jpsmit/archive/2007/03/21/wcf-fault-contracts.aspx

这篇关于返回 WCF 自定义错误异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 09:52