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;

                
            }
        }
    }

    结果如下图:

  • 相关阅读:
    minimsg升级扩展
    一起学习Avalonia(十三)
    @Import注解源码
    Python入门随记(3)
    NET WebApi 后端重定向指定链接
    Net Nlog 持久化到数据库
    NetCore Xunit单元测试依赖注入
    VS 调试时,提示无法启动iis服务器
    NET 反射,对可空类型动态赋值
    MSSQL 查询表结构
  • 原文地址:https://www.cnblogs.com/wxjnew/p/8276594.html
Copyright © 2011-2022 走看看