zoukankan      html  css  js  c++  java
  • webService 返回值问题

        前段时间在自己的笔记本上(开发环境是VS2008)测试用ExtJs+ASP.NET做一个信息系统框架,一切OK;

        在项目迁到公司电脑(VS2005)上之后发现问题了,webService返回的结果都是XML 格式的。弄了很久没有解决,后来干脆都用aspx做后台输出数据

        今天偶然看到人家用Response.Write 在后台webService输出数据,果然可以。

      

        测试代码如下:

      

       

    <%@ WebService Language="C#" Class="TestWebService" %>
    
    using System;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.Web.Script.Services.ScriptService]
    public class TestWebService  : System.Web.Services.WebService {
    
        
        //原先通过return方式返回的是XML格式的结果
        [WebMethod]
        public string HelloWorld_Old(string firstName, string lastName)
        {
            //return string.Format("Hello {0} {1}", firstName, lastName);
            return "{'success':true,'firstName':'" + firstName + "','lastName':'" + lastName + "'}";
        }
    
        //通过Response 输出string类型
        [WebMethod]
        public void HelloWorld(string firstName, string lastName)
        {
            //return string.Format("Hello {0} {1}", firstName, lastName);
            string rtnStr="{'success':true,'firstName':'" + firstName + "','lastName':'" + lastName + "'}";
            this.Context.Response.Write(rtnStr);
        }
    }
    
    
    
    
  • 相关阅读:
    SpringBoot 创建 console程序
    SpringBoot 参数检查 Controller中检查参数是否合法
    SpringBoot 使用maven创建springboot项目
    idea 社区版本创建javaweb项目 使用jetty
    idea 社区版本创建javaweb项目 使用tomcat
    mysql 主从 设置
    windows 使用nginx
    Linux 安装Nginx
    闭包小应用
    js小程序写法优化
  • 原文地址:https://www.cnblogs.com/nikyxxx/p/1703057.html
Copyright © 2011-2022 走看看