0
Answer

How to a object array parameter of a WebService/WebMethod to accept DBNull ?

Alberto

Alberto

16y
9.4k
1

I have a WebService/WebMethod that has a object array parameter. One of the elements of this array might contain a DBNull. When I try to pass an array with a DBNull element, I get the following message:

 

The type System.DBNull was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.

 

I have tried XmlInclude and SoapInclude with no success.

 

Web Service:

[WebMethod]

[System.Xml.Serialization.XmlInclude(typeof(DBNull))]

public string HelloWorld(object[] x) {

return "Hello World";

}

 

Consumer (Web Site):

object[] myarray = new object[1];

myarray[0] = DBNull.Value;

ServiceWS.Service serv = new ServiceWS.Service();

serv.HelloWorld(myarray);