silverlight ashx get

TaskStatus.ashx:

using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.IO;


namespace iCare.VQD.Workbench.Web
{
    /// <summary>
    /// Summary description for TaskStatus
    /// </summary>
    public class TaskStatus : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string result = string.Empty;
            
            Response response = new Response();
            response.Command = "taskstatus";
            response.ErrorCode = 500;


            string id = context.Request.QueryString["id"];
            string status=context.Request.QueryString["status"];


            string sql="update TaskExecLog set EndTime=getdate(),status={0} where ID ={1}";


            if (string.IsNullOrEmpty(id))   //判断id是否为空
            {
                response.ErrorCode=501;
            }
            else if (!string.IsNullOrEmpty(status )) //判断status是否为空
            {
                response.ErrorCode = 501;
            }


            int intId;
            if (!int.TryParse(id, out intId) || intId <= 0)  //判断id的格式是够是int类型
            {
                response.ErrorCode = 502;
            }
            
            bool boolStatus;
            if (!bool.TryParse(status, out boolStatus)) //判断status的格式是够是bool类型
            {
                response.ErrorCode = 502;
            }
            if (response.ErrorCode == 500)
            {
                sql = string.Format(sql, boolStatus ? 1 : 36, intId);

                DBManager dbManager = null;
                try
                {
                    dbManager = new DBManager(VQDUtil.GetConnectionString(), VQDUtil.GetDbProviderType());
                    dbManager.ExecuteNonQuery(sql, CommandType.Text);
                }
                catch (Exception ex)
                {
                    logger.Debug("更新数据异常", ex);
                }
            }


            result = XMLHelper.ToXmlString<Response>(response);


            context.Response.ContentType = "text/xml";
            Stream outStream = context.Response.OutputStream;
            using (StreamWriter writter = new StreamWriter(outStream))
            {
                writter.WriteLine(result);
            }
        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

}


XMLHelper:

    public static string ToXmlString<ITEM>(ITEM item)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(ITEM));
            using (MemoryStream memStream = new MemoryStream())
            {
                XmlWriterSettings setting = new XmlWriterSettings();
                setting.Encoding = Encoding.UTF8;
                using (XmlWriter writer = XmlWriter.Create(memStream, setting))
                {
                    serializer.Serialize(writer, item);
                    writer.Flush();
                    writer.Close();
                    memStream.Position = 0;
                    using (StreamReader reader = new StreamReader(memStream))
                    {
                        return reader.ReadToEnd();
                    }
                }
            }
        }


Response.cs:生成XML格式文件

<response command="xxxx">

       <errorcode>0</errorcode>

</response>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Serialization;


namespace iCare.VQD.Workbench.Web.Models.Shared.Http
{
    [XmlRoot("response")]
    public class Response
    {
        [XmlAttribute("command")]
        public string Command
        {
            get;
            set;
        }


        [XmlElement("errorcode")]
        public int ErrorCode
        {
            get;
            set;
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值