国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Flex與asp.net的WebService通訊

2024-07-10 13:08:16
字體:
供稿:網(wǎng)友
  • 本文來源于網(wǎng)頁設(shè)計(jì)愛好者web開發(fā)社區(qū)http://www.html.org.cn收集整理,歡迎訪問。
  •   本篇隨筆主要是關(guān)于flex與asp.net的webservice通訊,其中利用了soapheader。(如果你對(duì)soapheader不了解,可以參考webservice開發(fā)(一) 如何使用soap頭)。由此可見webservice在跨平臺(tái)方面的優(yōu)勢(shì)。

      asp.net的webservice代碼

    using system;
    using system.web;
    using system.web.services;
    using system.web.services.protocols;

    [webservice(namespace = "http://davidfan.cnblogs.com")]//名稱空間應(yīng)該和flex中定義相同
    [webservicebinding(conformsto = wsiprofiles.basicprofile1_1)]
    public class service : system.web.services.webservice
    {
        public validatesoapheader header;
        [webmethod]
        [soapheader("header")]
        public string helloworld()
        {
            if (header == null)
            {
                return "請(qǐng)?zhí)峁?yàn)證信息.";
            }
            else
            {
                if (header.name == "admin" && header.password == "admin")
                {
                    if (header.exdate < datetime.now)
                    {
                        return "帳號(hào)過期";
                    }
                    else
                    {
                        return "驗(yàn)證成功";
                    }
                }
                else
                {
                    return "用戶名或密碼錯(cuò)誤";
                }
            }
        }

    }

    /**//// <summary>
    /// 繼承自soapheader的自定義類
    /// </summary>
    public class validatesoapheader : system.web.services.protocols.soapheader
    {
        public validatesoapheader()
        {
        }
        public validatesoapheader(string name, string password, datetime dt)
        {
            this.name = name;
            this.password = password;
            this.exdate = dt;
        }

        private string name;
        public string name
        {
            get { return name; }
            set { name = value; }
        }

        private string password;
        public string password
        {
            get { return password; }
            set { password = value; }
        }

        private datetime exdate;
        public datetime exdate
        {
            get { return exdate; }
            set { exdate = value; }
        }
    }

      flex的mxml、as代碼

      mxml

    <?xml version="1.0" encoding="utf-8"?>
    <mx:application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontfamily="simsun" fontsize="12">
    <mx:script>
    <![cdata[
        import webserviceutility.info;
        import mx.rpc.events.faultevent;
        import mx.rpc.events.resultevent;
        import mx.rpc.soap.soapheader;
       
        private function sendrequest():void
        {
            var content:info = new info();
            content.name = username.text;
            content.password = password.text;
            content.exdate = new date(2010, 3, 10);
            //關(guān)鍵在qname的構(gòu)造函數(shù)
            //第一個(gè)參數(shù)要和.net的webservice的名稱空間相同
            //第二個(gè)參數(shù)要和.net的webservice的繼承自soapheader的自定義類名稱相同
            var qname:qname = new qname("http://davidfan.cnblogs.com","validatesoapheader");
            var header:soapheader = new soapheader(qname,content);
           
            ws.clearheaders();
            ws.addheader(header);
            ws.helloworld();
        }
        private function onresult(event:resultevent):void{
                result.text= event.result.tostring();
        }
        private function onfault(event:faultevent):void{
                result.text= event.message.tostring();
        }
    ]]>
    </mx:script>
    <mx:webservice id="ws" wsdl="http://localhost:9200/website2/service.asmx?wsdl"
    result="onresult(event)" fault="onfault(event)"/>
    <mx:textinput id="username" x="98" y="94"/>
    <mx:textinput id="password" x="98" y="124"/>
    <mx:label x="29" y="98" text="用戶名:"/>
    <mx:label x="29" y="128" text="密 碼:"/>
    <mx:button x="98" y="184" label="調(diào)用" click="sendrequest()"/>
    <mx:label x="29" y="156" text="結(jié) 果:"/>
    <mx:textinput id="result" x="98" y="154"/>
    </mx:application>

      as

    package webserviceutility
    {
            public class info{
                //該類名稱可以和.net中的validatesoapheader不同
                //但字段要對(duì)應(yīng)拼寫相同
                public var name:string;
                public var password:string;
                public var exdate:date;
            }
    }
    發(fā)表評(píng)論 共有條評(píng)論
    用戶名: 密碼:
    驗(yàn)證碼: 匿名發(fā)表
    主站蜘蛛池模板: 马尔康县| 磴口县| 卢氏县| 曲松县| 锡林郭勒盟| 金昌市| 宿迁市| 勃利县| 黄平县| 剑河县| 车险| 邮箱| 普格县| 伊宁县| 乌海市| 洪洞县| 衡东县| 永川市| 克东县| 吉林省| 布尔津县| 阿勒泰市| 曲阜市| 柳江县| 北宁市| 县级市| 怀安县| 万年县| 南丹县| 上高县| 安义县| 古田县| 绥中县| 类乌齐县| 财经| 通海县| 永春县| 拉萨市| 运城市| 齐齐哈尔市| 米泉市|