0

I have a solution containing several projects:

  1. Class Library with DataContracts definitions
  2. WCF Service Library (referencing 1)
  3. WPF UserControl Library
  4. WPF Client App (with service reference to 2 and reference to 3)

When I use proxy generation with service reference in the WPF Client App, data entities are generated in that project. Next I have WPF User Controls that I use in the WPF Client App and those controls are in a separate project for re-usability. I would like to pass data from the Client App to the UserControls based on some actions.

My question is, how can I reference the same Data entities in both WPF Client App and WPF UserControl library. In the UserControl library I can put a reference to the DataContract project, but those are different type from the data types produced with the proxy in the Client App. Right now im using dynamic in my UserControls and when I pass data from the ClientApp to the UserControls the binding resolves just fine. But i dont like that approach. I want to be able to use generics in my UserControls.

Im aware that if I have access to all of the projects (services and client) I can user ChannelFactory and reference the same DataContracts in all project, but my question now is regarding the scenario where the proxy is generated with a service reference.

So any ideas and best practices on how to share the same data types between different projects?

thanks

  • The service reference config window has an option "Reuse types in referenced assemblies". – Lee O. Oct 31 '14 at 22:02
  • hi @LeeO. , so I have a service reference in the Client App which generates the proxy with all the data types form the DataContracts declared in the WCF Service. Lets say that i have a class `Category` now im my Client App (from the service reference). How can I declare a property in the UserControl Library with that same `Category` data type? How do I share the data types accross projects when they are generated by the service reference in the Client App? – stack jack sharper Oct 31 '14 at 22:08
  • 1
    They don't have to be generated by the service reference. You can add a reference to your class library with DataContract defnitions and then select the "Reuse types in referenced assemblies". Instead of generating new classes on the client it will create the proxy using references to the classes in your class library. Now you can reference the class library in your user control project as well. – Lee O. Oct 31 '14 at 22:12
  • @LeeO. I see what you mean. That will work. But that is if we have the DataContract Project in our solution to reference it. Can you please advise what would be the approach to take if we only have the WCF service exposed by some external URL, meaning we would only have the data types generated along with the proxy in the Client App. How do we then share that data types with eht UserControl library? – stack jack sharper Oct 31 '14 at 22:21
  • 1
    You wouldn't be able to create a UserControl library that could be used with other projects if they need a reference to the classes generated in your main client project by the service reference. Because of this, you may as well just add the UserControls in a folder in the main client project instead of a separate project. Otherwise you'd have to have a cyclical reference UserControl -> Client -> UserControl. – Lee O. Oct 31 '14 at 22:27
  • You could add the service reference to the UserControl library? – Lee O. Oct 31 '14 at 22:30
  • I dont think its a good idea to add a service reference in the UserControl library. I imagined it being independent. But i guess you are right with your previous comment, keeping the usercontrols in the main project if DataContract project is not avaiable to be referenced, or "reuse types in referenced asseblies" if it is available. thanks – stack jack sharper Oct 31 '14 at 22:36

0 Answers0