Expand my Community achievements bar.

Update on Flex Consuming Web Service by ASP.NET

Avatar

Level 1

Good evening to the community,

I finally identified what was the error that explote the data transfer, Now Not show the message error.

What does is load the Datagrid but the data never loads.

If somebody can view the code and help me on identify the possible reason its going to be very appreciated

Thanks

Flex Code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
    backgroundGradientColors="[0xFFFFFF, 0xFFFFFF]">

    


       
        <mx:Script>
            <![CDATA[

                import mx.controls.Alert;
                import mx.rpc.events.FaultEvent;
                import mx.rpc.events.ResultEvent;
                import mx.rpc.soap.mxml.WebService;
                import mx.managers.CursorManager;
            

                /**
                * @bindable
                * @private
                * @property Will hold the data passed from the web service.
                */
                [Bindable]
                private var _xmlData:XML;

                /**
                * @private
                * Connects and calls the getPlayers() method from our web service.
                */
                private function clickHandler(event:MouseEvent):void
                {
                    CursorManager.setBusyCursor();
                    event.target.enabled = false;

                    var service:WebService = new WebService();
                    service.addEventListener(ResultEvent.RESULT, serviceResultHandler);
                    service.addEventListener(FaultEvent.FAULT, serviceFaultHandler);
                    service.loadWSDL("http://www.placespr.com/PLACESPR/placesService2.asmx?WSDL");
                    service.GetTitleData();
                }

                /**
                * @private
                * Stores the loaded data in an XML object and displays the DataGrid.
                */
                private function serviceResultHandler(event:ResultEvent):void
                {
                    CursorManager.removeBusyCursor();
                    _xmlData = XML(event.result);
                    this.dataGrid.visible = true;
                }

                /**
                * @private
                * Displays any possible errors that might occur when
                * trying to connect to our web service.
                */
                private function serviceFaultHandler(event:FaultEvent):void
                {
                    CursorManager.removeBusyCursor();
                    Alert.show(String(event.fault), "Error");
                    this.loadBtn.enabled = true;
                }

            ]]>
        </mx:Script>

        <mx:VBox horizontalCenter="0" verticalCenter="0"
               horizontalScrollPolicy="off" verticalScrollPolicy="off">

               <mx:Button id="loadBtn" label="Load/Display Data" width="700"
                   click="clickHandler(event);"/>
               <mx:DataGrid id="dataGrid" width="100%" height="200"
                   visible="false" dataProvider="{_xmlData.*}">
                   <mx:columns>
                       <mx:DataGridColumn headerText="ID"
                           dataField="emp_num" width="30"/>
                       <mx:DataGridColumn headerText="Name"
                           dataField="strstore_id" width="120"/>
                       <mx:DataGridColumn headerText="Score"
                           dataField="strvoucher_id" width="70"/>
                       </mx:columns>
               </mx:DataGrid>

        </mx:VBox>

</mx:Application>

ASP.NET WEB SERVICE:

<%@ WebService Language="VB" Class="placesService2" %>

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data
Imports System.Data.SqlClient

<WebService(Namespace:="http://placespr.com/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
Public Class placesService2
    Inherits System.Web.Services.WebService
   
    Public Class TitleInfo
        Public strTitleName As String
        Public strstore_id As String
        Public strvoucher_id As String
    End Class
       
   
    <WebMethod()> _
   Public Function GetTitleData() As TitleInfo()

        Try
            'create dataset
            Dim dsTitleData As New DataSet

            'create connection
            Dim objCon As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("dsn").ConnectionString)
            'create data adapter
            Dim cmdSQL As SqlDataAdapter = New SqlDataAdapter("SELECT emp_num, store_id, voucher_id FROM voucher", objCon)
            'fill dataset using data adapter
            cmdSQL.Fill(dsTitleData, "emp_num")

            'create object array, using row count as upper dim
            Dim objTitles As TitleInfo() = New TitleInfo(dsTitleData.Tables(0).Rows.Count - 1) {}
           

            'loop through dataset to add data to object array
            Dim intRsCount As Int16
            For intRsCount = 0 To dsTitleData.Tables(0).Rows.Count - 1
                objTitles(intRsCount) = New TitleInfo
                objTitles(intRsCount).strTitleName = dsTitleData.Tables(0).Rows(intRsCount)("emp_num")
                objTitles(intRsCount).strstore_id = dsTitleData.Tables(0).Rows(intRsCount)("store_id")
                objTitles(intRsCount).strvoucher_id = dsTitleData.Tables(0).Rows(intRsCount)("voucher_id")
                     
            Next

            'return object array
            Return objTitles

        Catch exp As Exception
            Throw
        End Try

    End Function

End Class

Thanks

evick

1 Reply

Avatar

Level 3

Try tracing the event.result to see if the data is being populated correctly.