zoukankan      html  css  js  c++  java
  • VS2013开发asmx接口返回一个自定义XML

    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;

                
            }
        }
    }

    结果如下图:

  • 相关阅读:
    man arch
    封装 pyinstaller -F -i b.ico excel.py
    Python比较两个excel文档内容的异同
    运维工具
    python封装成exe
    OCP内容
    OCP
    操作系统
    转:铁大树洞APP视频讲解和原型演示
    2020.3.31——针对超能陆战队铁大树洞项目的匿名特点分析
  • 原文地址:https://www.cnblogs.com/wxjnew/p/8276594.html
Copyright © 2011-2022 走看看