Web Service Proxy Problem!
-
Hi folks, Consider a
MyEntity
class that's being marked asSerializableAttribute
. The object is exposed to the outer world through the following web method:[WebMethod()] [SoapHeader("Credentials")] [SoapDocumentMethod(Use=SoapBindingUse.Encoded)] public MyEntity GetMyEntity() { //get the entity and return the object. }
Well, I've to mark the web method withSoapDocumentMethodAttribute
, or else, the XMLSerializer doesn't have any idea of how to serialize/deserialize the object. I've also altered the reference.cs file (the proxy file generated for the web service automatically) so that it will uses my business_objects.dll to handle objects, the file that hosts the MyEntity class. The problem is that whenever theGetMyEntity()
function is called, the service proxy tries to construct the object using the properties exposed on MyEntity class, using the default constructor of the class. How am I supposed to instruct the proxy to use the class constructors to get the job done? How am I supposed to control the serialization/deserialization process of the entities? Please keep in mind that theMyEntity
class uses circular references, and therefore, theXMLSerilizer
or Literal encoding *cannot be used* to handle the issue. Any help would be highly appreciated, TIA, Mehdi -
Hi folks, Consider a
MyEntity
class that's being marked asSerializableAttribute
. The object is exposed to the outer world through the following web method:[WebMethod()] [SoapHeader("Credentials")] [SoapDocumentMethod(Use=SoapBindingUse.Encoded)] public MyEntity GetMyEntity() { //get the entity and return the object. }
Well, I've to mark the web method withSoapDocumentMethodAttribute
, or else, the XMLSerializer doesn't have any idea of how to serialize/deserialize the object. I've also altered the reference.cs file (the proxy file generated for the web service automatically) so that it will uses my business_objects.dll to handle objects, the file that hosts the MyEntity class. The problem is that whenever theGetMyEntity()
function is called, the service proxy tries to construct the object using the properties exposed on MyEntity class, using the default constructor of the class. How am I supposed to instruct the proxy to use the class constructors to get the job done? How am I supposed to control the serialization/deserialization process of the entities? Please keep in mind that theMyEntity
class uses circular references, and therefore, theXMLSerilizer
or Literal encoding *cannot be used* to handle the issue. Any help would be highly appreciated, TIA, MehdiKeep in mind there are 2 classes involved in this case. On the server your MyEntity class exists as you have defined it. On the client there is a MyEntity class created when you generate the WebReference this class is a simple data class that just has public fields defined which match the public properties of the class defined on the server. When you write a web service, it is really just a collection of static methods which return simple data objects.
I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
-
Keep in mind there are 2 classes involved in this case. On the server your MyEntity class exists as you have defined it. On the client there is a MyEntity class created when you generate the WebReference this class is a simple data class that just has public fields defined which match the public properties of the class defined on the server. When you write a web service, it is really just a collection of static methods which return simple data objects.
I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
I think you missed the part that I said: "I've also altered the reference.cs file (the proxy file generated for the web service automatically) so that it will use my
business_objects.dll
to handle objects, the file that hosts the MyEntity class." This means that those classes you've mentioned do not exist any more. It now uses mybusiness_objects.dll
on the client (and server)... So what? What am I supposed to do to handle the Serializing/Deserializing the objects as needed? TIA, Mehdi -
I think you missed the part that I said: "I've also altered the reference.cs file (the proxy file generated for the web service automatically) so that it will use my
business_objects.dll
to handle objects, the file that hosts the MyEntity class." This means that those classes you've mentioned do not exist any more. It now uses mybusiness_objects.dll
on the client (and server)... So what? What am I supposed to do to handle the Serializing/Deserializing the objects as needed? TIA, MehdiMehdi Mousavi wrote:
What am I supposed to do to handle the Serializing/Deserializing the objects as needed?
You aren't. The proxy classes are designed to just instantiate a data class they weren't intended to do what you are trying to do. I'd write a wrapper around the proxy class that converts between your objects and the proxy object data objects. That would probably get you the closest to what you are trying to accomplish.
Using the GridView is like trying to explain to someone else how to move a third person's hands in order to tie your shoelaces for you. -Chris Maunder