Re: Class with no default constructor being passed through SOAP

Tech-Archive recommends: Fix windows errors by optimizing your registry



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


.



Relevant Pages

  • Re: Custom type property in property editoe (like Font in Control)
    ... The third parameter to the InstanceDescriptor constructor is a boolean ... Animated vector graphics system ... Do YOU know maybe how to change behavior of designer serialization. ... "Frank Hileman" wrote: ...
    (microsoft.public.dotnet.framework.windowsforms.designtime)
  • Re: Difficult generics issue (generifying jakarta commons)
    ... you cannot invoke the constructor with a type parameter that is determined ... There is the class PrototypeFactory, ... Serializable in its constructor, and produce a clone of it each time its ... createmethod is invoked, using serialization. ...
    (comp.lang.java.programmer)
  • Re: abstract static methods (again)
    ... serialization frameworks. ... It is already required that a Serializable class has a no-arg constructor. ... But this is not required at compile time. ...
    (comp.lang.java.programmer)
  • Re: Difficult generics issue (generifying jakarta commons)
    ... There is the class PrototypeFactory, ... Serializable in its constructor, and produce a clone of it each time its ... createmethod is invoked, using serialization. ... where arg is of type T (which is in turn the type parameter of the ...
    (comp.lang.java.programmer)
  • Re: Please help: Serious problems with code generation of user controls
    ... I created a UserControl-derived class, added some controls to it, and then ... The only peculiarity may be the IContainer constructor. ... the first time you instance a problematic UserControl ... > in all our control classes, the Controls serialization problem does not ...
    (microsoft.public.dotnet.framework.windowsforms.designtime)