WCF:在嵌套服务调用中保留内部异常

时间:2018-02-27 08:54:02

标签: c# .net wcf

我有一个以这种方式运行WCF调用的解决方案:

Web API - (WCF) - >主要服务 - (WCF) - >子服务。

让我们说Sub服务抛出异常我希望主项目也抛出异常。最后,我想将完整的堆栈跟踪报告给主项目。

问题是我没有设法让被叫子服务堆栈跟踪超过1 WCF调用。

如果可能的话,我希望在抛出异常时有类似的东西:

SubService.ThrowException()
SubService.ProcessRequest()
==== End of inner exception ====
MainService.CallSubService()
...
MainService.ProcessRequest()
==== End of inner exception ====
MainProject.CallMainService()
...

[ServiceContract]
public interface IMainService
{
    [OperationContract]
    [FaultContract(typeof(System.Exception))]
    JobInformation ProcessJob(JobInformation info);
}

[ServiceContract]
public interface ISubService
{
    [OperationContract]
    [FaultContract(typeof(System.Exception))]
    JobInformation ProcessJob(JobInformation info);
}


public class SubServiceClient
{    
    public JobInformation ProcessJob(JobInformation info)
    {
        return (Service.ProcessJob(info));
    }
}

1 个答案:

答案 0 :(得分:0)

最简单的方法:我将使用解决方法。

data Mag a b t where
  Pure :: t -> Mag a b t
  Map :: (x -> t) -> Mag a b x -> Mag a b t
  Ap :: Mag a b (t -> u) -> Mag a b t -> Mag a b u
  One :: a -> Mag a b b

instance Functor (Mag a b) where
  fmap = Map

instance Applicative (Mag a b) where
  pure = Pure
  (<*>) = Ap

traverse2 :: forall t a b c f. (Traversable t, Biapplicative f)
          => (a -> f b c) -> t a -> f (t b) (t c)
traverse2 f0 xs0 = go m m
  where
    m :: Mag a x (t x)
    m = traverse One xs0

    go :: forall x y. Mag a b x -> Mag a c y -> f x y
    go (Pure t) (Pure u) = bipure t u
    go (Map f x) (Map g y) = bimap f g (go x y)
    go (Ap fs xs) (Ap gs ys) = go fs gs <<*>> go xs ys
    go (One x) (One y) = f0 x
    go _ _ = error "Impossible"

但请注意序列化异常的大小。您可能必须配置WCF以接受更大的数据。