WCF 故障未正确传播到客户端

发布于 2024-08-28 11:06:32 字数 1023 浏览 4 评论 0原文

我们有以下 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,但客户端收到的只是基础数据故障异常

未收到合同规定的故障的原因可能是什么?

We've got the following WCF Service Contracts:

[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
{
}

We are calling the async version of ValidateUser in the client side and we are throwing a FaultException<Fault1> on the server, but all the client receives is the base FaultException.

What can be the reason the contractually-specified fault is not being received?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凌乱心跳 2024-09-04 11:06:32

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

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

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

We found now why. We are generating the fault from a Service Behaviour using the ProvideFault method. There we use code similar to the example at IErrorHandler.ProvideFault in msdn

The only difference was that we weren't passing the right action on the Message.CreateMessage overload. We copied exactly what gets generated in the case that we manually throw the fault and voila.

My excuses for not giving that last detail :-)

绿萝 2024-09-04 11:06:32

您能向我们展示您的通话的 catch 语句吗?合同和一切对我来说看起来都很好......

你按什么顺序检查错误?在检查 FaultExceptionCommunicationException 之前,您必须先检查 FaultException - 您可能有任何机会这个顺序不知何故混淆了?

当您调用该方法的同步版本时它是否有效?

Can you show us the catch statements for your call? The contract and everything looks fine to me...

In which order do you check for faults?? You would have to check for FaultException<Fault1> before checking for FaultException or CommunicationException - any chance you might have that order mixed up somehow?

Does it work when you call the sync version of the method?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文