Existing Class Library to Service (WCF/Asmx?)

Nate Bross

Contributor
Joined
Apr 6, 2005
Messages
601
Location
Chicago, IL
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
 
Last edited:
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?
 
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:
C#:
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
 
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.
 
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.
 
Back
Top