可以使用 ASP.NET 2.0 创建 REST Web 服务 [英] Possible to create REST web service with ASP.NET 2.0

查看:44
本文介绍了可以使用 ASP.NET 2.0 创建 REST Web 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 ASP.NET 2.0 创建 REST Web 服务?我发现的文章和博客条目似乎都表明,使用 ASP.NET 创建 REST Web 服务需要带有 WCF 的 ASP.NET 3.5.

Is it possible to create a REST web service using ASP.NET 2.0? The articles and blog entries I am finding all seem to indicate that ASP.NET 3.5 with WCF is required to create REST web services with ASP.NET.

如果可以在 ASP.NET 2.0 中创建 REST Web 服务,您能否提供一个示例.

If it is possible to create REST web services in ASP.NET 2.0 can you provide an example.

谢谢!

推荐答案

我实际上已经使用 asp.net 2.0 创建了一个 REST Web 服务.它与创建网页真的没有什么不同.

I have actually created a REST web service with asp.net 2.0. Its really no different than creating a web page.

当我这样做的时候,我真的没有太多时间研究如何用 asmx 文件来做,所以我在标准的 aspx 文件中做了.我知道这样做会带来额外的开销,但作为第一次修订,这很好.

When I did it, I really didn't have much time to research how to do it with an asmx file so I did it in a standard aspx file. I know thier is extra overhead by doing it this way but as a first revision it was fine.

protected void PageLoad(object sender, EventArgs e)
{
    using (XmlWriter xm = XmlWriter.Create(Response.OutputStream, GetXmlSettings()))
    {
        //do your stuff
        xm.Flush();
    }
}

    /// <summary>
    /// Create Xml Settings object to properly format the output of the xml doc.
    /// </summary>
    private static XmlWriterSettings GetXmlSettings()
    {
        XmlWriterSettings xmlSettings = new XmlWriterSettings();
        xmlSettings.Indent = true;
        xmlSettings.IndentChars = " ";
        return xmlSettings;
    }

这应该足以让您入门,我稍后会尝试发布更多内容.

That should be enough to get you started, I will try and post more later.

此外,如果您需要对 Web 服务进行基本身份验证,则可以完成,但如果您不使用活动目录,则需要手动完成.

Also if you need basic authentication for your web service it can be done, but it needs to be done manually if you aren't using active directory.

这篇关于可以使用 ASP.NET 2.0 创建 REST Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆