Use of xmlelement in Asp.net Webserver

Source: Internet
Author: User

1. Create a toostemp. asmx File

2. Define a method to obtain product categories:

[Webmethod (enablesession = true, description = "Get product classification")]
Public getprodclasssresponse getprodclass (string merchantuid, string shopcode)
{
Getprodclassbll bllgetprodclass = new getprodclassbll ();
Return bllgetprodclass. getprodclass (merchantuid, shopcode );
}

3. Create a producerGetprodclasssresponseReality:

[Serializable] [xmlroot ("Getprodclasssresponse")]Public ClassGetprodclasssresponse {PrivateGetprodclass;PublicGetprodclass {Set{Getprodclass =Value ;}Get{ReturnGetprodclass ;}}}

4. create other entities and use the following:

View code

     Public   Class  Getprodclass {  Private   Bool  _ Resulttype;  Public   Bool  Resulttype {  Get { Return  _ Resulttype ;}  Set {_ Resulttype =Value ;}}  Private   String  _ Errorcode;  Public   String  Errorcode {  Get { Return  _ Errorcode ;}  Set {_ Errorcode = Value ;}}  Private   String _ Errormsg;  Public   String  Errormsg {  Get { Return  _ Errormsg ;}  Set {_ Errormsg = Value ;}}  Private List <proprodclass> _ Prodclass; [xmlelement (elementname = "  Prodclass "  )]  Public List <proprodclass> Prodclass {  Set  {_ Prodclass = Value ;}  Get  {  Return  _ Prodclass ;}}}  Public   Class  Proprodclass { Private   String  _ Id;  Public   String  Id {  Get { Return  _ Id ;}  Set {_ Id = Value ;}}  Private   String  _ Classname;  Public  String  Classname {  Get { Return  _ Classname ;}  Set {_ Classname = Value ;}}  Private   String  _ Parent;  Public   String  Parent {  Get {Return  _ Parent ;}  Set {_ Parent = Value ;}}  Private   Int  _ Kind;  Public   Int  Kind {  Get { Return  _ Kind ;}  Set {_ Kind =Value ;}}} 

5. If there is no [xmlelement (elementname = "prodclass:

The generated XML is as follows:

View code

<? XML version = "  1.0  " Encoding = "  UTF-8  " ?> <Getprodclasssresponse xmlns: xsi = "  Http://www.w3.org/2001/XMLSchema-instance  " Xmlns: XSD = " Http://www.w3.org/2001/XMLSchema  " Xmlns = "  Http://tempuri.org/  " > <Getprodclass> <resulttype> True </Resulttype> <prodclass> <proprodclass> <ID> 8dc84093-55ef-4bb7-b49e-27a5f285fb03 </ID> <classname> focus </classname> <parent> 0 </Parent> <kind> 1 </Kind> </proprodclass> <ID> d63f2b60-c869-48d6-8af5-ecdc03ec1177 </ID> <classname> Material </classname> <parent> 0 </Parent> <kind> 1 </Kind> </proprodclass> <ID> bb007659-c359-404b-ba86-f4bc73305b42 </ID> <classname> Fort Petersburg </classname> <parent> 0 </Parent> <kind> 1 </Kind> </proprodclass> <ID> release </ID> <classname> cold release </classname> <parent> d63f2b60-c869-48d6-8af5-ecdc03ec1177 </parent> <kind> 2 </Kind> </proprodclass> <ID> ba8acf1c-5af7-464f-bd15-f4b65296961f </ID> <classname> Category </classname> <parent> d63f2b60-c869-48d6-8af5-ecdc03ec1177 </parent> <kind> 2 </Kind> </proprodclass> <ID> c8143a27-51b9- 4421 -99a7-3e6a3b682d28 </ID> <classname> sweet spot </classname> <parent> 8dc84093-55ef-4bb7-b49e-27a5f285fb03 </parent> <kind> 2 </Kind> </proprodclass> <ID> salad </ID> <classname> salad </classname> <parent> salad </parent> <kind> 2 </Kind> </proprodclass> <ID> 647f4aea-74c0- 4883 - 8972 -45f181401574 </ID> <classname> commandid </classname> <parent> d63f2b60-c869-48d6-8af5-ecdc03ec1177 </parent> <kind>2 </Kind> </proprodclass> <ID> portable </ID> <classname> Fort meters </classname> <parent> bb007659-c359-404b-ba86-f4bc73305b42 </parent> <kind> 2 </Kind> </proprodclass> <ID> safedog Fort </ID> <classname> bb007659-c359-404b-ba86-f4bc73305b42 </parent> <kind> 2 </Kind> </proprodclass> <ID> fried </ID> <classname> fried </classname> <parent> fried </parent> <kind>2 </Kind> </proprodclass> <ID> 0fb3b45c-bba4- 4289 -Aa24-decc79128aec </ID> <classname> Fort Petersburg </classname> <parent> bb007659-c359-404b-ba86-f4bc73305b42 </parent> <kind> 2 </Kind> </proprodclass> </prodclass> </getprodclass> </getprodclasssresponse>

6. If it is added, the generated result is as follows:

View code

<? XML version = "  1.0  " Encoding = " UTF-8  " ?> <Getprodclasssresponse xmlns: xsi = "  Http://www.w3.org/2001/XMLSchema-instance  " Xmlns: XSD = "  Http://www.w3.org/2001/XMLSchema  " Xmlns = "  Http://tempuri.org/  " > <Getprodclass> <resulttype> True </Resulttype> <prodclass> <ID> 8dc84093-55ef-4bb7-b49e-27a5f285fb03 </ID> <classname> </classname> <parent> 0 </Parent> <kind> 1 </Kind> </prodclass> <ID> d63f2b60-c869-48d6-8af5-ecdc03ec1177 </ID> <classname> Material </classname> <parent> 0 </Parent> <kind> 1 </Kind> </prodclass> <ID> bb007659-c359-404b-ba86-f4bc73305b42 </ID> <classname> Fort Petersburg </classname> <parent> 0 </Parent> <kind>1 </Kind> </prodclass> <ID> 56505c54-e81b-46d6-a1ad-257fd43356c5 </ID> <classname> cold partition </classname> <parent> d63f2b60-c869-48d6-8af5-ecdc03ec1177 </parent> 2 </Kind> </prodclass> <ID> ba8acf1c-5af7-464f-bd15-f4b65296961f </ID> <classname> Category </classname> <parent> d63f2b60-c869-48d6-8af5-ecdc03ec1177 </parent> <kind> 2 </Kind> </prodclass> <ID> c8143a27-51b9- 4421 -99a7-3e6a3b682d28 </ID> <classname> sweet spot </classname> <parent> 8dc84093-55ef-4bb7-b49e-27a5f285fb03 </parent> <kind> 2 </Kind> </prodclass> <ID> salad </ID> <classname> salad </classname> <parent> 8dc84093-55ef-4bb7-b49e-27a5f285fb03 </parent> 2 </Kind> </prodclass> <ID> 647f4aea-74c0- 4883 - 8972 -45f181401574 </ID> <classname> commandid </classname> <parent> d63f2b60-c869-48d6-8af5-ecdc03ec1177 </parent> <kind> 2 </Kind> </prodclass> <ID> skip </ID> <classname> Fort meters </classname> <parent> bb007659-c359-404b-ba86-f4bc73305b42 </parent> <kind> 2 </Kind> </prodclass> <ID> 41682ed6-746e-450e-b689-528a4a9751ef </ID> <classname> wuwuwubao </classname> <parent> bb007659-c359-404b-ba86-f4bc73305b42 </parent> 2 </Kind> </prodclass> <ID> 0193b67f-97de-46c4-807b-c86d4572dfa9 </ID> <classname> fried </classname> <parent> Category </parent> 2 </Kind> </prodclass> <ID> 0fb3b45c-bba4- 4289 -Aa24-decc79128aec </ID> <classname> Fort Petersburg </classname> <parent> bb007659-c359-404b-ba86-f4bc73305b42 </parent> <kind> 2 </Kind> </prodclass> </getprodclass> </getprodclasssresponse>

7. For example:

If this sentence exists, the generated XML is less specific. The list definition can be removed.

8. [xmlelement (elementname = "prodclass1")] can be used to define the actual name of an entity.

Private list <proprodclass> _ prodclass;

[Xmlelement (elementname = "prodclass1")]
Public list <proprodclass> prodclass
{
Set
{_ Prodclass = value ;}
Get {
Return _ prodclass;
}
}

In such a sentence, a prodclass1 entity is generated.

 

 

Related Article

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.