【问题标题】:WCF Fault not being propagated to the client properlyWCF 错误未正确传播到客户端
【发布时间】:2010-04-09 15:45:22
【问题描述】:

我们有以下 WCF 服务合同:

[ServiceContract(Namespace = "http://example.com", Name = "Service1")]
public interface IService1
{      
  [OperationContract]
  [FaultContract(typeof(Fault1))]
  ValidateUserResult ValidateUser(
                       string username, 
                       string password);
}

[ServiceContract(Namespace = "http://example.com", Name = "Service1")]
public interface IService1Async
{      
    [OperationContract(AsyncPattern = true)]
    [FaultContract(typeof(Fault1))]
    IAsyncResult BeginValidateUser(
                       string username, 
                       string password, 
                       AsyncCallback callback, 
                       object userState);

    ValidateUserResult EndValidateUser(IAsyncResult asyncResult);
}

[DataContract(Namespace = "http://example.com")]
public class Fault1
{
}

我们在客户端调用 ValidateUser 的异步版本,我们在服务器上抛出一个FaultException<Fault1>,但客户端收到的只是基本FaultException

没有收到合同规定的过错可能是什么原因?

【问题讨论】:

    标签: wcf fault contracts


    【解决方案1】:

    我们现在找到了原因。我们正在使用 ProvideFault 方法从服务行为生成故障。在那里,我们使用类似于IErrorHandler.ProvideFault in msdn 示例的代码

    唯一的区别是我们没有对Message.CreateMessage 重载传递正确的操作。我们准确地复制了在我们手动抛出错误的情况下生成的内容,瞧。

    我没有提供最后一个细节的借口:-)

    【讨论】:

      【解决方案2】:

      您能否向我们展示您调用的 catch 语句?合同和一切在我看来都很好......

      您按什么顺序检查故障?您必须检查FaultException<Fault1> 之前 检查FaultExceptionCommunicationException - 有没有可能您的订单以某种方式混淆?

      调用同步版本的方法是否有效?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-19
        相关资源
        最近更新 更多