David's profileprowyh's spaceBlogLists Tools Help

Blog


    May 05

    关于WebService.htc的一个小问题

    要在IE浏览器中访问Web Services,必须要将webservice.htc以如上的形式嵌入页面中。webservice.htc是Microsoft开发的访问远程Web Services的客户端proxy component。
     
    由于IE7增强了安全方面的设置,有可能会造成webservice.htc不能正常装载。如图所示,要在IE7中正常装载Behavior文件,必须Enable Binary and script behaviors。
     
    April 05

    Puzzled by WebServices

    在BMP系统中,针对Web环境中用户认证的非安全性,设计了一种基于CHAP(Challenge Handshake Authentication Protocol)协议的用户认证模型,但在用WebServices实现身份验证时,发现在WebServices中,HttpContext.Current.Session为Null!而ASP.NET的其它对象如Application、Server、Request、Response却都可访问!
     
    为什么没有Session对象呢?在折腾了一天之后,发现问题出在WebMethodAttribute。WebMethodAttribute的EnableSession属性在默认情况下为false,只要将EnableSession设置为true,就可以访问Session对象了。
     
    [WebMethod Description="This is a service method which used to return the value of a session variable.", EnableSession=true]
    public string GetSessionValue()
    {
        string sValue = (string)HttpContext.Current.Session["aVariable"];
        return sValue;
    }
     
    MSDN上说,如果不需要用到Session,则应将EnableSession设置为false,这样可以提高性能。所以其初始值为false。如果需要用到Session,则需要将其设置为true,否则Session对象在WebServices中不可访问。
    March 23

    关于WebServices的一点注记

    《Core C# and .NET》以及.NET的资料关于DataList.asmx文件的WebService指令的说明:Class="LevenSite.DataList, DataList"意味WebService的代码封装在DataList.dll文件中,这样DataList.asmx文件就只有这一行指令,这样即可有效保护代码的知识产权。
     
    DataList.asmx.cs文件源代码:
     
    using System;
    using System.Web;
    using System.Web.Services;
    namespace LevenSite
    {
        [WebService(Namespace = "http://www.levensoft.com/WebService")]
        public class DataList : System.Web.Services.WebService
        {
            public DataList()
            {
                InitializeComponent();
            }
        }
        [WebMethod(Description="GetDataList")]
        public string GetDataList()
        {
            return "Hello World!";
        }
    }
     
    这段代码如果放在DataList.asmx中,一切正常,如果调用此WebService,则得到"Hello World!"的结果,但如果将此段代码另存为DataList.asmx.cs并且编译为DataList.dll,从而在DataList.asmx文件中按开头给出的WebService指令调用的话,则出错,原因是DataList.dll文件格式无效。
     
    经过多次努力后,发现问题出在.NET的版本上,这种代码分离方式只有.NET 2.0支持,.NET 1.x是不支持的!这一点,《Core C# and .NET》以及.NET的文档都没有提及!