欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

flex调用webservice中的自定义类的方法

程序员文章站 2022-06-19 13:14:51
复制代码 代码如下: public class returnresult { public int curindex { get; set; } public datata...
复制代码 代码如下:

public class returnresult
{
public int curindex { get; set; }
public datatable idxlist { get; set; }
}
//测试数据库连接
[webmethod(description = "!!!测试数据库连接,链接字符串在web.config中")]
public bool conectdb()
{
strcon = configurationsettings.appsettings["sqlconduke"];
conn = new sqlconnection(strcon);
try
{
conn.open();
return true;
}
catch (exception)
{
return false;
}
finally
{
conn.close();
}
}

复制代码 代码如下:

[webmethod(description = "根据 <b>照片名</b> 获得详细数据(datatable),strtb,eg:panview;strimgname,eg:20131019072740-0000150")]
public datatable getinfobyimgname(string strtb, string strimgname)
{
bool ifcon = conectdb();
if (ifcon)
{
string sql_bfcar = "select * from dbo." + strtb + " where imagename like '%" + strimgname + "%'";
da = new sqldataadapter(sql_bfcar, conn);
myds = new dataset();
da.fill(myds);
return myds.tables[0];
}
else
{
return null;
}
}


[webmethod(description = "根据 <b>照片名</b> 获得所在link的所有数据(returnresult),strtb,eg:panview;strimgname,eg:20131019072740-0000150")]
public returnresult getlinkdtbyimgname(string strtb, string strimgname)
{
returnresult returnresult = new returnresult();
bool ifcon = conectdb();
if (ifcon)
{
returnresult.curindex = convert.toint32(getinfobyimgname(strtb, strimgname).rows[0][0]);
string strlinkguid = getinfobyimgname(strtb, strimgname).rows[0][1].tostring();
string sql_bfcar = "select * from dbo." + strtb + " where linkguid like '%" + strlinkguid + "%'";
da = new sqldataadapter(sql_bfcar, conn);
myds = new dataset();
da.fill(myds);
returnresult.idxlist = myds.tables[0];
return returnresult;
}
else
{
return null;
}
}

flex代码:
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<s:application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minwidth="955" minheight="600" creationcomplete="application1_creationcompletehandler(event)">
<fx:script>
<![cdata[
import mx.collections.arraycollection;
import mx.controls.alert;
import mx.events.flexevent;
import mx.rpc.events.faultevent;
import mx.rpc.events.resultevent;

public var arr:arraycollection=new arraycollection();
public var aaa:string=new string();

protected function webservice1_faulthandler(event:faultevent):void
{
alert.show(event.fault.tostring());
}
protected function getlinkdtbyimgnamehandler(event:resultevent):void
{
// aaa=this.myweb.getlinkdtbyimgname.lastresult.curindex;
// arr=this.myweb.getlinkdtbyimgname.lastresult.idxlist.tables.table.rows;

aaa=event.result.curindex;
arr=event.result.idxlist.tables.table.rows;
alert.show(aaa+" "+arr.length.tostring());
}


protected function application1_creationcompletehandler(event:flexevent):void
{
myweb.getlinkdtbyimgname("panview","20131019072740-0000150");
}

]]>
</fx:script>
<fx:declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<s:webservice id="myweb" wsdl="http://10.19.1.55/serverpano/webserviceduke.asmx?wsdl" fault="webservice1_faulthandler(event)">
<s:operation name="getlinkdtbyimgname" result="getlinkdtbyimgnamehandler(event)"></s:operation>
</s:webservice>
</fx:declarations>
</s:application>