A method for flex to invoke a custom class in WebService

Source: Internet
Author: User
Tags xmlns

 flex How to call a custom class in WebService, here's a good example, and friends who don't know can refer to the following

The code is as follows: public class returnresult  {  public int Curindex {get; set;}   Public DataTable idxlist {get; set;}  } //test database connection   [WebMethod (Description = "!!! Test database connection, link string in Web.config ")]  public bool Conectdb ()   {  Strcon = configurationsettings.appsettings[" Sqlconduke "];  conn = new SqlConnection (Strcon);  try , { . Open ();  return true; }  catch (Exception)   {  return false; }  finally  {&nbsp ; Conn. Close (); } }    code is as follows: [WebMethod (Description = "Get detailed data (DataTable) based on <b> photo name </b>, 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 = NE W DataSet ();nbsp Da. Fill (myds);  return myds. tables[0]; }  else  {  return null; } }      [WebMethod (Description = "Based on <b> photo name </b> get all the data (returnresult) of the link, 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 CodeThe:  code is as follows: <?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= "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>  <!--place non-visual elements (such as services, value objects) here-->  <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>   
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.