Re: Class with no default constructor being passed through SOAP
- From: "Sahil Malik [MVP]" <contactmethrumyblog@xxxxxxxxxx>
- Date: Mon, 6 Jun 2005 13:31:59 -0400
Dave,
The reason you get this error is because Web services use XmlSerialization
to send your objects across - which means your class is bound by all
restrictions XmlSerializer puts on it - default public constructor being one
of them.
How do you get around it? Well you should not get around it. But if you
must, wrap this class in another class with a pub-def-constructor, and
implement IXmlSerializable to customize the xml serialization behavior. In
an End to End .NET shop you may even send a stream of bytes using
BinaryFormatter.
Or you can just send a bytestream as a function return and
serialize/deserialize using binaryformatter - though that assumes that your
client has .NET, which breaks the web service philosophy.
- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------
---------------
"Dave A" <dave@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:uxFOc8paFHA.2664@xxxxxxxxxxxxxxxxxxxxxxx
I have a class that does not have a default constructor. The nature of the
class inherently excludes it from having one and to put one in will
blatantly misrepresent the object that it is modelling.
So having said that, how do I get it to go through SOAP when SOAP requires
that the class has a default constructor?
In ASP.NET 2 the error message is "<class> cannot be serialized because it
does not have a parametless constructor" (please note the typo/spelling
error) A similar error occurs in ASP.NET 1.x
(Implementing my own IXmlSerializable interface that does not help. I tried
it.)
Regards
Dave A
.
- Follow-Ups:
- Prev by Date: Re: Create a web from an existing web application
- Next by Date: Hiding Schema on a Webservice that returns a dataset
- Previous by thread: Re: Create a web from an existing web application
- Next by thread: Re: Class with no default constructor being passed through SOAP
- Index(es):
Relevant Pages
|