zoukankan      html  css  js  c++  java
  • c# webservice接口 输出xml

    using System;
    using System.Web;
    using System.Collections;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.IO;
    using System.Xml.Serialization;
    using System.Text;
    using System.Collections.Generic;


    /// <summary>
    /// WebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class WebService : System.Web.Services.WebService {

        public WebService () {

            //如果使用设计的组件,请取消注释以下行
            //InitializeComponent();
        }

        [WebMethod]
        public string HelloWorld()
        {
            //return "Hello World";
            List<ccd> bb = new List<ccd>();
            //ArrayList<
           // ArrayList bb = new ArrayList();
            for (int i = 0; i < 3; i++)
            {
                ccd ccd1 = new ccd();
                ccd1.cc1 = i.ToString();
                ccd1.cc2 = (i + 5).ToString();
                // ccd1.cc3 = (i + 6).ToString();
                ccd2 cccd2 = new ccd2();

                cccd2.kk1 = (i + 7).ToString();
                cccd2.kk2 = (i + 8).ToString();
                ccd1.cc4 = cccd2;
                bb.Add(ccd1);

            }
            //ccd t_item = new ccd();
            //t_item.cc1 = "7754";
            //t_item.cc2 = "爆米花机";
            //MemoryStream ms = new MemoryStream();
            //XmlSerializer xml = new XmlSerializer(t_item.GetType());
            //xml.Serialize(ms, t_item);

            MemoryStream ms = new MemoryStream();
            XmlSerializer xml = new XmlSerializer(bb.GetType());
            xml.Serialize(ms, bb);
            //return bb;

            return Encoding.UTF8.GetString(ms.ToArray()).Replace("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"","");

        }

        [WebMethod(Description = "求和的方法")]
        public double addition(double i, double j)
        {
            return i + j;
        }

       
    }

    public class ccd
    {
        public string cc1;
        public string cc2;
        //public string cc3;
        public ccd2 cc4;
    }

    public class ccd2
    {
        public string kk1;
        public string kk2;
      
    }

  • 相关阅读:
    ideaIU-2017.1.1.exe安装、注册、汉化IntelliJ IDEA
    504 Gateway Timeout 异常
    Windows下80端口被进程System占用的解决方法
    D2Admin基本使用
    MySQL 教程
    Element 插件
    VSCode-Element-Helper
    ECharts 教程
    JSP 教程
    Kotlin 教程 Android 官方开发语言
  • 原文地址:https://www.cnblogs.com/wzg0319/p/2435468.html
Copyright © 2011-2022 走看看