WCF重试代理 [英] WCF Retry Proxy

查看:111
本文介绍了WCF重试代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和试图找到实现WCF试的最好办法挣扎。我希望让客户体验尽可能干净。有其中我知道(见下文)两种方法。我的问题是:?有没有办法,我错过了第三种方法也许有这这样做的普遍接受的方式

I'm struggling with trying to find the best way to implement WCF retries. I'm hoping to make the client experience as clean as possible. There are two approaches of which I'm aware (see below). My question is: "Is there a third approach that I'm missing? Maybe one that's the generally accepted way of doing this?"

办法#1 :创建一个实现服务接口的代理。对于每次调用代理,实施重试

Approach #1: Create a proxy that implements the service interface. For each call to the proxy, implement retries.

public class Proxy : ISomeWcfServiceInterface
{
    public int Foo(int snurl)
    {
        return MakeWcfCall<int>(() => _channel.Foo(snurl));
    }

    public string Bar(string snuh)
    {
        return MakeWcfCall<string>(() => _channel.Bar(snuh));
    }

    private static T MakeWcfCall<T>(Func<T> func)
    {
        // Invoke the func and implement retries.
    }
}



方法2 :更改MakeWcfCall()(上图)公众,并有消费代码直接发送FUNC。

Approach #2: Change MakeWcfCall() (above) to public, and have the consuming code send the func directly.

我不喜欢的方式#1是具有更新什么每次界面的变化代理类。

What I don't like about approach #1 is having to update the Proxy class every time the interface changes.

我不喜欢的方式#2什么是不必换他们呼吁在FUNC客户端。

What I don't like about approach #2 is the client having to wrap their call in a func.

我缺少一个更好的办法?

Am I missing a better way?

修改

我已经张贴在这里的答案(见下文)的基础上,接受的答案我指出了正确的方向。我想我会分享我的代码,在一个答案,帮助别人通过什么我不得不工作,通过工作。希望它帮助。

I've posted an answer here (see below), based on the accepted answer that pointed me in the right direction. I thought I'd share my code, in an answer, to help someone work through what I had to work through. Hope it helps.

推荐答案

我这样做很有型的事,我使用.NET的的RealProxy 类。

I have done this very type of thing and I solved this problem using .net's RealProxy class.

使用 RealProxy ,您可以使用您提供的界面在运行时创建一个实际的代理。从调用代码这是因为如果他们使用的是的IFoo 频道,但实际上它是一个的IFoo 来的代理,然后你得到一个机会来拦截任何方法,属性,构造函数的调用等等...

Using RealProxy, you can create an actual proxy at runtime using your provided interface. From the calling code it is as if they are using an IFoo channel, but in fact it is a IFoo to the proxy and then you get a chance to intercept the calls to any method, property, constructors, etc…

RealProxy ,然后你可以重写Invoke方法拦截对WCF方法的调用和处理的CommunicationException等。

Deriving from RealProxy, you can then override the Invoke method to intercept calls to the WCF methods and handle CommunicationException, etc.

这篇关于WCF重试代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆