In this case, there are three custom classes: House, salehouse, and house. Salehouse and salehouse are subclasses of the house class. One method in WebService is to return the house class.
1 [Webmethod]
2 Public House get ( Int Houseid)
3 {
4 Return House. Get (houseid );
5 }
The following error is reported during debugging:
System. invalidoperationexception: An error occurred while generating the XML document. --->
System. invalidoperationexception:
It should not be type yajukelib. Housing. salehouse.
Use the xmlinclude or soapinclude attribute to statically specify unknown types.
I checked the information on the Internet and said that the attribute was to be used.Xmlincludeattribute. Then, add [xmlinclude (typeof (house)] To the house class and WebService. The above error is reported. [Serializable] does not work.
Search again on msdnXmlincludeattributeThe definition is as follows: Allow xmlserializer to recognize types when it serializes or deserializes objects. So I think it is because the type returned by the method is actually a subclass of the house class. xmlserializer can only identify the parent class during serialization, but cannot recognize the subclass, which leads to serialization errors. So I added [xmlinclude (typeof (salehouse)] and [xmlinclude (typeof (house)] to WebService at the same time to solve the problem.
[Xmlinclude ( Typeof (Salehouse)]
[Xmlinclude ( Typeof (House)]
Public Class Houseservice: system. Web. Services. WebService