King

business intelligence ,is my love。

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1:利用XmlDocument生成一个xml文档返回,代码如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml;

namespace WebServiceTest
{
    /// <summary>
    /// Test 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
    // [System.Web.Script.Services.ScriptService]
    public class Test : System.Web.Services.WebService
    {

        [WebMethod]
        public int Test1(int a,int b)
        {
            return a+b;
        }
        [WebMethod]
        public int Test2(int a, int b)
        {
            return a - b;
        }
        [WebMethod]
        public XmlDocument Test3(int a, int b)
        {
         string xmlstr = "<nm values='" + a + "' date='2014-1-2' count='14' page='" + b + "'>"
          + "<domain>张三</domain>"
          + "<domain>张三</domain>"
          + "<domain>张三</domain>"
          + "<domain>张三</domain>"

          + "</nm>";


            //关键
            XmlDocument XmlDoc = new XmlDocument();
            XmlDoc.LoadXml(xmlstr);
            return XmlDoc;

            
        }
    }
}

结果如下图:

posted on 2018-01-12 16:44  kingstudy  阅读(363)  评论(0)    收藏  举报