flash remoting 連接 VB webservice

Flash remoting connect to vb.net web services(基於 AS2.0  &  flashgateway.dll [framework1.1])
利用flash 8 pro作測試
首先安裝 flashremoting_components_flash8.msi
再安裝 flashremoting-net-win-en2.exe , 安裝這個後會自動創建flashremoting虛擬目錄
開始>執行>inetmgr > 默認網站>flashremoting>右鍵屬性>創建應用程序
>http:\\localhost\flashremoting\samples\html\default.htm
測試三個samples
如果第三個samples運行不到, 將C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin 加到環境變數 path中 , 因為裏面有remoting要用到的wsdl.exe
 
開一個新虛擬目錄 > tester ,裏面有以下檔案
bin
      -  flashgateway.dll
test.fla
test.asmx
web.config
gateway.aspx
 
bin 目錄的flashgateway.dll可以到先前flashremoting\bin 找到,把它copy貼入
 
先創建gateway.aspx, 很簡單的一句
<%@ Page %>
 
創建web.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
            <system.web>
        <compilation    
                 defaultLanguage="vb"
                 debug="true"
        />
        <httpModules>
    <add name="GatewayController" type="FlashGateway.Controller.GatewayController,flashgateway" />
        </httpModules>
        <globalization    
                        requestEncoding="utf-8"    
                        responseEncoding="utf-8"    
     />
</system.web>
</configuration>
 

主要是<httpModules>
 
test.asmx
<%@ WebService Language="VB" Class="test" %>
Imports System
Imports System.Data
Imports System.Web.Services
Public Class test : Inherits WebService
        <WebMethod()> Public Function Getit() As String
                Return "123"
        End Function
End Class
 
 
flash remoting connector 的連接方法如下:
test.fla
 
/*
//第一個方法 : 利到flashgateway.dll ,通過test.asmx?wsdl 在bin創建一test.dll(沒有namespace)及test.cs再調用其test.dll的Getit方法
stop();
//-------------------------------------------------------------
import mx.remoting.Service;
import mx.rpc.FaultEvent;
import mx.remoting.PendingCall;
import mx.rpc.ResultEvent;
import mx.rpc.RelayResponder;
mx.remoting.debug.NetDebug.initialize();
var myService:Service = new Service("http://localhost/tester/gateway.aspx", null, "http://localhost/tester/test.asmx?wsdl", null, null);
var pc:PendingCall = myService.Getit();
pc.responder = new RelayResponder(this, "Getit_Result", "Getit_Fault");
trace("這時,信息還未返回");
function Getit_Result(re:ResultEvent):Void {
trace(re.result);
}
function Getit_Fault(fe:FaultEvent):Void {
trace("接收到錯誤");
}
*/

 
*
//第二個方法:    利到flashgateway.dll ,通過test.asmx?wsdl 在bin創建一test.dll(沒有namespace)及test.cs再調用其test.dll的Getit方法
stop();
import mx.data.components.RemotingConnector;
mx.remoting.debug.NetDebug.initialize();
var my_rc:RemotingConnector = new RemotingConnector();
my_rc.addEventListener("result", Getit_Result);
my_rc.addEventListener("status", Getit_Status);
my_rc.gatewayUrl = "http://localhost/tester/gateway.aspx";
my_rc.methodName = "Getit";
my_rc.serviceName = "http://localhost/tester/test.asmx?wsdl";
my_rc.suppressInvalidCalls = true;

function init():Void {
if (this.inited != undefined) {
    return;
} else {
    var inited:Boolean = true;
    my_rc.params = null;
    my_rc.trigger();
}
}
init();

function Getit_Result(ev:Object) {
trace(ev.target.results) ;}
function Getit_Status(stat:Object) {
        trace("接收到錯誤");
}

/*

 
 
第三個方法:
首先將bin 的test.dll,test.cs 刪去(如果有的話)
接著copy wsdl.exe 和 vbc.exe 到tester目錄
不知道wsdl.exe , vbc.exe在那?
cmd > dir /s wsdl.exe 找找
發現
vbc.exe > C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
wsdl.exe > C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin
 
然後cmd  >tester 目錄 >運行以下代命令
wsdl /l:vb /n:testvb /out:test.vb http://localhost/tester/test.asmx?wsdl
得到test.vb
再執行
vbc /t:library /out:test.dll /r:system.data.dll /r:system.web.dll /r:system.dll /r:system.xml.dll /r:system.web.services.dll test.vb
得到vb編譯,命名空間為testvb的test.dll
 
test.fla
/*
//第三個方法 :    不需用到flashgateway.dll , 通過bin的test.dll(預先編譯)調用Getit方法
stop();
import mx.remoting.Service;
import mx.rpc.FaultEvent;
import mx.remoting.PendingCall;
import mx.rpc.ResultEvent;
import mx.rpc.RelayResponder;
mx.remoting.debug.NetDebug.initialize();
var myService:Service = new Service("http://localhost/tester/gateway.aspx", null, "testvb.test", null, null);
var pc:PendingCall = myService.Getit();
pc.responder = new RelayResponder(this, "Getit_Result", "Getit_Fault");
trace("這時,信息還未返回");
function Getit_Result(re:ResultEvent):Void {
trace(re.result);
}
function Getit_Fault(fe:FaultEvent):Void {
trace("接收到錯誤");
}
*/



 
 
 
測試成功的話將會trace回  :   123
"接收到錯誤"的話可以查看 視窗>其它面板>netconnection debugger
或者可以查看bin > flash.log
 
---------------------------------------------------------------------------
 
 
其實還有一種連接方式,就是調用remoting class ,以下我們嘗試用這個連接方式連接webservie查詢數據庫.需要文件如下:
bin
      -  flashgateway.dll
test2.fla
con2mdb.asmx
web.config
gateway.aspx
test.mdb
 
gateway.aspx , web.config 內容不變.
test.mdb 隨便弄些數據吧

mdb

 
 
 
 
 
 
 
con2mdb.asmx
<%@ WebService Language="VB" Class="con2mdb" %>

imports System.Web
imports System.Web.Services
imports System.Web.Services.Protocols
imports System.Data
imports System.Data.OleDb    

Public Class con2mdb    
<WebMethod()> public Function GetData() As DataSet
Dim oConn As OleDbConnection
Dim oComm As OleDbCommand
Dim oData As OleDbDataAdapter
Dim resultSet As New DataSet
Dim oConnect, oQuery As String

oConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data    

Source=C:\\Inetpub\\wwwroot\\tester\test.mdb"    
oQuery = "SELECT * FROM main"
oConn = New OleDbConnection(oConnect)
oComm = New OleDbCommand(oQuery, oConn)
oData = New OleDbDataAdapter(oQuery, oConn)
oConn.Open()
oData.Fill(resultSet, "accessTest")
oConn.Close()

Return resultSet
End Function
End Class
 
 
test.fla
先從視窗內建元件庫>remoting>拉一個remoting class 出來
拖一個remotingconnector 組件到場景,命名為my_rc , ctrl+f7組件檢測器配置如下
 
 
場境第一幀:
stop();    
import mx.data.components.RemotingConnector;    
import mx.remoting.Service;    
import mx.rpc.FaultEvent;    
import mx.remoting.PendingCall;    
import mx.rpc.ResultEvent;    
import mx.rpc.RelayResponder;    
mx.remoting.debug.NetDebug.initialize();    


my_rc.addEventListener("result", GetData_Result);    
my_rc.addEventListener("status", GetData_Status);    

function init():Void {    
if (this.inited != undefined) {    
        return;    
} else {    
        var inited:Boolean = true;    
        my_rc.params = null;    
        my_rc.trigger();    
}    
}    
init();    


function GetData_Result(re:ResultEvent):Void {    
trace("連接成功");    
}    
function GetData_Fault(fe:FaultEvent):Void {    
trace("接收到錯誤");    
}    
 
ctrl-enter 看到輸出 :  連接成功
查看bin資料夾有沒有con2mdb.dll
有的話即是成功編譯, 記得con2mdb.asmx 最後return 的是什麼?
return 的是一個resultSet 的Dataset
怎檥顯示到flash上?去組件拉一個list component出來,命名為lb
my_rc 組件檢測器>結構
因為return回來的是一個complex object ,我要的是裏面的accessTest
my_rc 組件檢測器>繫結
將accessTest綁定到list的dataProvider, ctrl-enter 結果如下:
 
 
 
 
 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章