Groups | Blog | Home
all groups > dotnet web services > december 2006 >

dotnet web services : Accessing Class Properties


senfo
12/13/2006 4:13:19 PM
When designing a DAL (data access layer), I designed the methods to
return custom classes that contain properties. Example:

public class Employee
{
private string _name;

public string Name
{
get { return _name; }
}

public Employee()
{
_name = "Employee Name";
}
}

[...]

public static Employee GetEmployee()
{
return new Employee();
}

The requirements have since changed completely from what they were
originally and I'll have to design the DAL as a web service. I didn't
think this would be a big deal, but apparently properties are not
serialized as XML as I had expected.

There is quite a bit of custom code developed in the DAL, so I'm
obviously looking for the simplest approach to modifying my original
code into something that can be accessed through a web service.

Does anybody have any suggestions on how to implement this design change
as seamless as possible?

Thank you in advance,

--
Scott M.
12/13/2006 8:36:51 PM
How about implementing webmethods that get/set internal class property
values?


[quoted text, click to view]

senfo
12/14/2006 6:44:25 AM
[quoted text, click to view]

I have nothing against this idea, per sey; I'm just trying to avoid
having to rewrite quite a bit of custom code, if that's possible. If
there are no other alternatives, I'll just have to do it.

Thank you for the response,

--
senfo
12/14/2006 8:24:13 AM
[quoted text, click to view]

The thing that doesn't make sense to me is that it's possible to, for
example, return a DataSet object from a WebMethod. The DataSet object
is useless without its properties, so how does .NET manage to
successfully serialize a DataSet object for use on .NET clients, whereas
the class I wrote is not?

Thank you again,

--
Scott M.
12/14/2006 4:49:30 PM
A WebService class itself doesn't expose properties over the web (as you
found out), but you can certainly create your own serializable class that
can be returned from a WebService. Once the consumer recieves and
de-serailizes it, the consumer would be able to access the properties.
BUT - - you must make the class serializable yourself correctly to ensure
that the properties will serialize/deserialize correctly.

It's the difference between calling a WebService class and returning a
serialized class (not the same thing).


[quoted text, click to view]

AddThis Social Bookmark Button