tags:

views:

577

answers:

3

VS WCF integration has nice option "Reuse types in refrenced assemblies". The problem is that I need the same but for the current assembly. Some of the types are already defined in my assembly and I need to reuse them.

Usage scenario:

  1. I have assembly, and have TypeA here.
  2. I add Service Reference ot it, and one of the methods returns type that is fully compatible with TypeA(properties, name).
  3. Add Service Reference generates proxy, but it recreate new TypeA within.

On the step 3 I need proxy that will return TypeA. Not new TypeA.

A: 

Could you clarify your scenario? Normally when presented with a question like "how do I use a type defined in the assembly I'm currently writing", my answer would be "just use it." What is preventing you from just 'new'ing up the type, or otherwise using it, since you're in the same assembly?

Bruce
I have updated question with scenatio
Mike Chaliy
Ok, got it. Thinking...
Bruce
I'm pretty sure this is doable, but I'm not sure exactly how. One thing you can try is to use svcutil.exe to extract the metadata from your assembly, and use the same tool to generate a proxy from that metadata, and use the /reference: parameter to tell it to specifically use the types from your assembly. However, I can appreciate that you probably want a more turnkey solution. I'm a little disappointed that it doesn't "just work" when used as you describe.
Bruce
+2  A: 

If I understand what you want to do, then it's an scenario I commonly run into, and well, WCF does have a decent answer to: Just don't use SvcUtil / WS Service Reference wizards.

If you have most of the contract classes already defined in your client side (be that because you have a shared assembly or because you have equivalent classes defined on your project), you might as well just go to the next step and either import the complete service contract in code form or simply redefine it on the client side.

There's nothing that forces you to use svcutil and friends, just define your interface and either use the channel model directly (i.e. ChannelFactory<T> and friends) or, if you prefer to use proxy classes, just create your own ClientBase<T>-derived class. It's really very easy and it will save you trouble in the long run.

tomasr
Yep, I have done this way, slightly after asking. Anyway thanks for your time.
Mike Chaliy
A: 

There is an easy way to share types between client and service, just by adding reference to shared type assembly to your client BEFORE adding the service reference.

You can find the detailed scenario and sample project there:

http://blog.walteralmeida.com/2010/08/wcf-tips-and-tricks-share-types-between-server-and-client.html

Walter Almeida