Type Conversion to Original Type

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a class library, lets call it ClassLib, which contains an abstract
class, lets call it Entity, that acts as sort of a marker.

I have a web service that consumes the ClassLib to make use of the Entity
abstract class. The web service has a class, lets call it MyEntity that
inherits from ClassLib.Entity and a method called GetEntitites that returns
an array of MyEntity classes.

Next I have a web application that consumes the web service. Of course the
reference to the web services makes a proxy classes called Entity and
MyEntity. The problem is that these types are NOT the same types as the web
service referenced therefore when the GetEntities method is called it returns
the array of MyEntity objects as defined by the proxy.

This is all well and expected. I understand all of what I just explained.
Now here comes my question...

How can I convert each of the MyEntity objects returned from the web service
into the original type that the web serviced used from the ClassLib?

NOTE: I do not want to change anything in the references.cs file of the
reference to the web service.

I looked at the System.ComponentModel.TypeConverter class but that just
doesn't work. Casting doesn't work as well. Any ideas?
 
Demetri said:
How can I convert each of the MyEntity objects returned from the web service
into the original type that the web serviced used from the ClassLib?

NOTE: I do not want to change anything in the references.cs file of the
reference to the web service.

I had a similar situation, but I resolved by editing the references
file of proxy classes to return the appropriate types. It works fine,
but if you ever refresh the web service, you have to do it again.

I don't beleive there will be an automatic way to what you want. One
possibility would be to include in your MyEntity class a constructor
that takes an instance of the web proxy class. Then when you get one
back from the web service, just pass it to the constructor:

Dim obj As New MyEntity(instanceofwebproxyclass)

Then inside the constructor, take the properties of the web proxy class
and assign them to your custom class. Depending on the size of your
class, this may be tedious, though.
 
the simple answers is you can't without writing your own conversion code.

In next version of visual studio you will be able to share libraries across
the web service boundary in this manner.

HTH

Ollie Riches
 
Back
Top