Action Script 3.0 İle Webservicelere Bağlanma

18 Ağustos 2009 – 10:35

AS3ten, .NET veya php de olabilir, webserviceler aracılığıyla bağlanmak için şöyle bir fonksiyon kullanıyoruz. Diyelim ki ben asp.net projeme bağlanmak istiyorum. Bunun için bağlantı yoluna .asmx uzantılı dosyamdaki bağlanmak istediğim webmethodun adını yazıyorum.

 

function sendService (id,cmd,args)

{

            //bağlantı yolu

            var scriptRequest:URLRequest = new URLRequest(”http://localhost:81/ws.asmx/sendCMD”);

            var scriptLoader:URLLoader = new URLLoader();

            var Vars:URLVariables = new URLVariables();

                                    

            scriptLoader.addEventListener(Event.COMPLETE, handleLoadSuccessful);

            scriptLoader.addEventListener(IOErrorEvent.IO_ERROR, handleLoadError);

           

            //methoda gönderecegimiz parametreler                  

            Vars.to =id;

            Vars.cmd=cmd;

            Vars.args=args;

           

//post olarak gönderiyoruz veri alacaksak get kullanıyoruz             

            scriptRequest.method = URLRequestMethod.POST;

            scriptRequest.data = Vars;

                                    

            scriptLoader.load(scriptRequest);

                                    

            function handleLoadSuccessful(e:Event):void

            {

                         trace(”mesaj gönderildi.”);

                        //eger kullandıgınız method bir şey döndürüyorsa bunu kullanmak için söyle yazın

                         trace(e.target.data);

            }

                                    

            function handleLoadError(e:IOErrorEvent):void

            {

                         trace(”mesaj gönderilemedi.”);

            }

}

Bookmark and Share

Post a Comment

Subscribe without commenting