0

Scenario I have a WebService(.asmx) in C#.Net. I included a class which inherits from SoapHeader class. I have a parameterized constructor in it but as I forgot to include a parameterless constructor, it generated following error when I updated the WebService proxy on client side:

   Error: User cannot be serialized because it does not have a parameterless constructor.

So I immediately included the parameterless constructor and the issue ended up.

Questions
Q1. I think serialization takes place during request and response, Is it the 'class type' being serialized here (which I don't think is possible as its object which is serialized)?
Q2. I am not able to access Parameterized constructor (gives error: Does not contain a constructor that takes 1 argument ) on client side. Why is that?

Its a simple class for learning purpose:

public class User : SoapHeader
{
    private string strUid;

    public User(string id)  // cannot access
    {
        strUid = id;
    }

    public User() { }   // included later

    public string UserID
    {
        get
        {
            return strUid;
        }
        set
        {
            strUid = value;
        }
    }
}
Sadiq
  • 786
  • 1
  • 10
  • 35
  • Possible duplicate of [Constructor in WCF DataContract not reflected on Client](http://stackoverflow.com/questions/6316118/constructor-in-wcf-datacontract-not-reflected-on-client) – vendettamit Apr 12 '16 at 20:16
  • Well it answers my Q2. but Q1. is not answered – Sadiq Apr 15 '16 at 06:46
  • Class types are published as meta in wsdl which serializer uses to detect the types of object. – vendettamit Apr 15 '16 at 10:45
  • Agreed, But why in above issued error It says: cannot be "SERIALIZED" .... What was it trying to serialize? when i was just updating my proxy for that Web Service and not actually requesting or getting an response – Sadiq Apr 15 '16 at 12:00
  • It might be a constraint in proxy generator for classes with no default constructor. That's why I prefer dynamic proxy with shared contracts in a separate project unless it's a public api. Also there are constraints with defining contracts so you may want to keep them handy. – vendettamit Apr 15 '16 at 12:16

0 Answers0