An error occurred when WebService generated the XML document. It should not be type XXXX. Use the xmlinclude or soapinclude attribute to statically specify unknown types.

Source: Internet
Author: User

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

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.