dizzytri99er
dizzytri99er

Reputation: 930

Calling a parameterless method from a web service error

I'm trying to call a web service method which returns an ID of a company

GetCompanyCommand companyRef = new GetCompany();

but I have a method in the web service that already exists and the constructor has a parameter

public GetCompanyCommand(Guid actCompanyId)
    {
        this.actCompanyId = actCompanyId;

    }

The problem is when i go to update the Web Service reference i am presented with an error that says the method cannot be serialised because it does not contain a parameterless constructor.

Now is there a way for me to fix this without changing the existing constructor? Because many other methods already call it.

Upvotes: 1

Views: 178

Answers (1)

Talha
Talha

Reputation: 19242

If your web service class has a constructor with parameter than it should have parameterless constructor. like

public GetCompany()
{

}

This is a limitation of XmlSerializer. Note that BinaryFormatter and DataContractSerializer do not require this - they can create an uninitialized object out of the ether and initialize it during deserialization.

During an object's de-serialization, the class responsible for de-serializing an object creates an instance of the serialized class and then proceeds to populate the serialized fields and properties only after acquiring an instance to populate.

Upvotes: 2

Related Questions