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;

                
            }
        }
    }

    结果如下图:

  • 相关阅读:
    PeCheck
    模拟木马
    青柠网络验证
    青柠网络验证一键合成工具(exe程序和网络验证合成)
    如果想看我以前发的文章,请到下面地址查看
    星空QQ音乐下载2.0 (可下载收费音乐)
    vmp分析文章
    星空QQ群1.0模块
    青柠网络验证
    Java之IO操作总结
  • 原文地址:https://www.cnblogs.com/wxjnew/p/8276594.html
Copyright © 2011-2022 走看看