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;

                
            }
        }
    }

    结果如下图:

  • 相关阅读:
    http请求的跨域
    事件驱动模型
    单例设计
    引用类型与垃圾回收
    注解开发
    Java的反射机制
    Android Listener 监听的几种写法
    人生必须有所规划,工作是好比马拉松
    Android 常用的常量
    Android 常见的广播 action常量
  • 原文地址:https://www.cnblogs.com/wxjnew/p/8276594.html
Copyright © 2011-2022 走看看