. NET error solution in XML serialization in Web Service

Source: Internet
Author: User

When we do web service, we often need to pass a list from the background to the foreground. in the list, if the basic type such as string is directly inserted, there is no problem. If we define a data class file by ourselves, the metadata of [serializable] is added to the definition of this class file, it is no problem to pass the class object to the foreground using web service. However, when we insert this object into a list and use web service to transfer this list, an error will occur.

The error message is as follows.

System. invalidoperationexception. ---> System. invalidoperationexception: Type bcanddac. user specified specifies that the specified parameter has been used successfully. Zookeeper zookeeper uses zookeeper to specify the zookeeper xmlinclude zookeeper soapinclude attribute to enable zookeeper.
Field System. xml. serialization. xmlserializationwriter. writetypedprimitive (string name, string NS, object o, Boolean xsitype)
Microsoft. xml. serialization. generatedassembly. xmlserializationwriter1.write1 _ object (string N, string NS, object o, Boolean isnullable, Boolean needtype)
Microsoft. xml. serialization. generatedassembly. xmlserializationwriter1.write2 _ arrayofanytype (Object O)
Microsoft. Xml. Serialization. GeneratedAssembly. IListSerializer. Serialize (Object objectToSerialize, XmlSerializationWriter writer)
Field System. Xml. Serialization. XmlSerializer. Serialize (XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- The exception is when there are too many rows when there are rows before the last ---
Field System. Xml. Serialization. XmlSerializer. Serialize (XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
Field System. Xml. Serialization. XmlSerializer. Serialize (XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
Field System. xml. serialization. xmlserializer. serialize (xmlwriter, object o, xmlserializernamespaces namespaces)
Field System. xml. serialization. xmlserializer. serialize (textwriter, object o, xmlserializernamespaces namespaces)
Field System. xml. serialization. xmlserializer. serialize (textwriter, object O)
Field System. Web. Services. Protocols. xmlreturnwriter. Write (httpresponse response, stream outputstream, object returnvalue)
Site system. Web. Services. Protocols. httpserverprotocol. writereturns (object [] returnvalues, stream outputstream)
Field System. Web. Services. Protocols. webservicehandler. writereturns (object [] returnvalues)
Site system. Web. Services. Protocols. webservicehandler. Invoke ()

On the surface, it is an error that the object cannot be serialized. But why is this. I did not think of the specific reason, but I found a solution, that is, to add the xmlinclude metadata before the Web service method. The Code is as follows.

[System. xml. serialization. xmlinclude (typeof (User)]

Then run it again and find that the Web Service is normal. You can identify the user class that I have defined.

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.