Question

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.

Was it helpful?

Solution

I'm not sure that it is possible using svcutil/add service reference, but as an alternative the .NET Framework has a class called MetadataResolver that allows you to get configuration at runtime from a MEX / wsdl endpoint.

Specifically you call the Resolve method returns a ServiceEndpointCollection instance. A ServiceEndpoint has a Behaviors property that returns the collection of behaviors as defined on the service.

In this case instead of having the class decorated with the attribute you call the service to retrieve your behaviors. This has the advantage of allowing you to define in one place (the service) the configuration for clients and the server and keep them in sync (as opposed to service config updates needed to be done on clients as well). The negatives are that you now make two calls when calling the service (though I've mitigated in the past by having a static instance and keeping the response from the Resolve method in memory) and you need to expose the service metadata.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top