1

A question someone asked in 2008, about proxy-generation of client-side behaviors, I'd like to repeat. I want custom client-side behaviors, decorated as attributes on service contracts or operations, to be "acknowledged" by Visual Studio (or svcutil) when I execute "discover" on the add-service-reference dialogue. The result would be a proxy that already has the client-side behaviors (and assembly references) added automagically.

That feature still seems unavailable as of VS 2010 SP1. Does VS 2012 do that? Is there a 3rd party tool that does that?

p.s. To be clear, I am not asking about extending WSDL capabilities. I don't expect the above trick would ever work for that. I am talking strictly in the context of the "discover" button within Visual Studio's in-built proxy generation capability.

4

1 回答 1

0

我不确定是否可以使用 svcutil/add 服务引用,但作为替代方案,.NET Framework 有一个名为MetadataResolver的类,它允许您在运行时从 MEX / wsdl 端点获取配置。

具体来说,您调用该Resolve方法会返回一个ServiceEndpointCollection实例。ServiceEndpoint 有一个Behaviors属性,该属性返回服务上定义的行为集合。

在这种情况下,您调用服务来检索您的行为,而不是用属性装饰类。这样做的好处是允许您在一个地方(服务)定义客户端和服务器的配置并使它们保持同步(与需要在客户端上完成的服务配置更新相反)。缺点是您现在在调用服务时进行了两次调用(尽管我过去通过拥有一个静态实例并将 Resolve 方法的响应保存在内存中来缓解)并且您需要公开服务元数据。

于 2012-10-26T15:30:48.390 回答