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;
  
}

转载于:https://www.cnblogs.com/wzg0319/archive/2012/04/06/2435468.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值