Nate Bross Posted October 9, 2008 Posted October 9, 2008 (edited) I have an existing class library, with alot of functionallity, I would like to expose these methods/biz objects as a service. I have several command line utilities that use this library as a normal reference, and the .exe and .dll reside in the same directory, but I'd like to be able to expose some of the data access methods as a service so I can access them via ASP.NET, WPF Browser, or Silverlight. [Point being that I'd like to "wrap" the functionallity in the class library in a service so I can update the .dll in the necessary folders and it will not require re-referencing my service or any of the command line apps I've written that already use the .dll version.] Which way will be the best implimentation a WCF Service (can you provide me any resources for getting started with WCF?) or a traditional Asmx Service? TIA Edited October 9, 2008 by Nate Bross Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Nate Bross Posted October 9, 2008 Author Posted October 9, 2008 One issue that I am having specifically is that WCF does not expose my entire object. My business objects, which contain mostly properties, and a few methods for loading those properties are not available on the WCF Client side. Should I create methods in my service for these few "data loading" methods in my business objects? Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Administrators PlausiblyDamp Posted October 10, 2008 Administrators Posted October 10, 2008 Which bits are / are not being exposed? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Nate Bross Posted October 10, 2008 Author Posted October 10, 2008 When I mark object with [DataContract] only the private objects are available on the Client Side and NO methods what-so-ever. If I mark with [OperationContract] I get the methods (as expected) but NO Properties. Simplified Class that is giving me trouble: public Class myClass { String myVal = String.Empty; public String MyVal { //get/set for myVal } // no parm constructor public myClass() {} public myClass(String val) { myVal = val; } public Boolean ValidMyVal() { if(myVal.Length > 5) return true; else return false; } } Problem being that from WCFClient I cannot use the Constructor with parms to set my value, and I cannot access the public properties to set the values myself. I can deal with the [DataContract] only providing access to its private members, but I think it should be exposing it's public properties, and only giving access to private memebrs via (get/set)ers in said properties. TIA Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
estump Posted October 16, 2008 Posted October 16, 2008 Try adding the [DataMember] attribute to the properties in your interface. Quote
Administrators PlausiblyDamp Posted October 16, 2008 Administrators Posted October 16, 2008 that is pretty much how it is designed, classes marked with [DataContract] are really designed as a way of passing information between systems and as such aren't expected to include functionality. [OperationContract] defines server side functionality. If the object existed server side but still exposed all the properties every single property assignment would involve a network trip and also require the server to maintain the state between calls. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Nate Bross Posted October 30, 2008 Author Posted October 30, 2008 I found this blog post on WCF: http://jimblogdog.blogspot.com/2008/06/wrap-your-existing-business-layer-with.html I have business objects that contain contain utility methods for easy of use. Methods to take a DataRow, or an XmlNode as input and return a new instance of the business object. I get that the [DataContract] is to represent data, and [serviceContract] is for providing functionallity. Another thing I just realised is that [DataMember] does not support read only properties, any thoughts on addressing this? I would very much like to avoid completely redesigning my business objects and data access layer. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.