Hi Kietvt
Im trying to passing web service array object. but it is not
working.
the error is : TypeError: Error #1009: Cannot access a property or
method of a null object reference.
can you please let me know wht is the issue.
.net code.
------------------
Service.vb
<WebMethod()> _
Public Function Addsample(ByVal ParamArray x() As Object) As
Integer
'ByVal ParamArray x() As Object
Dim intRowCount As Object
Dim strSQLselect As String = "Select id from mk where id=" & x
(0)
Try
Addsample = DAL1.Check_Availability(strSQLselect)
If x(0) = Addsample Then
intRowCount = DAL1.UpdatePersonalDetails(x)
Else
intRowCount = DAL1.insert(x)
End If
Catch ex As System.Exception
Throw ex
End Try
Return intRowCount
End Function
End Class
Dal1.vb
Public Shared Function insert(ByVal ParamArray I() As Object) As
Integer
Dim cmdObj As New SqlCommand
Dim intRowCount As Integer
Try
' Dim strSQLinsert As String = "insert into mk
(id,name,date1) values ('" & I(0) & "','" & I(1) & "','" & I(2) & "')"
Dim strSQLinsert As String = "insert into mk (id) values
('" & I(0) & "')"
cmdObj.CommandText = strSQLinsert
cmdObj.CommandType = CommandType.Text
cmdObj.Connection = DAL.GetDBConnection("07")
intRowCount = cmdObj.ExecuteNonQuery()
Return intRowCount
Catch ex As System.Exception
Throw ex
Finally
cmdObj.Connection.Close()
cmdObj.Dispose()
End Try
End Function
End Class
flex code :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<!--WEBSERVICE-->
<!--WEBSERVICE - SUBMIT -->
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.soap.LoadEvent;
import mx.collections.ArrayCollection;
import mx.managers.CursorManager;
import mx.utils.ArrayUtil;
import mx.rpc.soap.WebService;
private var p1:Array;
public function SubmitUseWebService():void {
CursorManager.setBusyCursor();
WS.addEventListener("load", SubmitLoadHandler);
WS.loadWSDL();
}
public function SubmitLoadHandler(event:LoadEvent):void {
p1.push(int(userid.text));
p1.push(Name.text);
p1.push(mDOB.text);
Alert.show(p1[0]);
WS.Addsample(p1);
}
public function SubmitResultHandler(event:ResultEvent):void {
var resultObj:Object = event.result as Object ;
var updated:Boolean = resultObj.SUCCESS ;
if (updated == true) {
Alert.show("Records Updated Successfully");
CursorManager.removeBusyCursor();
} else {
Alert.show("Records NOT Updated");
CursorManager.removeBusyCursor();
}
CursorManager.removeBusyCursor();
}
public function SubmitFaultHandler(event:FaultEvent):void {
Alert.show( "fault: "+ event.toString());
CursorManager.removeBusyCursor();
}
]]>
</mx:Script>
<!-- create Webservice -->
<mx:WebService id="WS" wsdl="http://localhost:1474/test/Service.asmx?
WSDL" useProxy="false"
fault="Alert.show(event.fault.faultString), 'Error'">
<mx:operation name="Addsample" result="SubmitResultHandler(event)"
fault="SubmitFaultHandler(event)"/>
</mx:WebService>
<mx:TextInput x="191" y="56" id="userid"/>
<mx:TextInput x="191" y="86" id="Name"/>
<mx:Button x="257" y="168" label="Submit" click="SubmitUseWebService
()"/>
<mx:Label x="75" y="58" text="ID"/>
<mx:Label x="75" y="88" text="Name"/>
<mx:Label x="75" y="118" text="DOB"/>
<mx:DateField x="191" y="116" id="mDOB"/>
</mx:Application>
On Nov 1, 5:00 pm, "kiet tuan" <[EMAIL PROTECTED]> wrote:
> Hi Harit,
> You can not cast res.getItemAt(0) to User object.
> you only use using us:Object = res.getItemAt(0);
>
> I tested already on .NET
>
> Regards,
> KietVT
>
> 2008/11/1 harit <[EMAIL PROTECTED]>
>
>
>
>
>
> > I have implemented a web service that returns ArrayList (Java) object
> > from AXIS + apache tomcat server.
> > I have implemented a method for my flex client to manipulate result of
> > the WS call.
> > Here it is...
>
> > public function resEvent(event:ListUsersResultEvent):void
> > {
> > var res:ArrayCollection = (ArrayCollection)(event.result);
> > var us:Object = res.getItemAt(0);
> > mx.controls.Alert.show(""+us.password + " " + us.id);
> > }
>
> > For ref. the java web service on server is returning ArrayList of User
> > objects.
> > I have User ActionScript class on client too.
>
> > Everything's fine except that when I typecast var us:User = (User)
> > (res.getItemAt(0)); it gives exceptions.
> > Just declaring and assigning by var us:Object = res.getItemAt(0);, I
> > am able to access public properties like id, password which are
> > essentially belong to User class and not Object class.
>
> > Can anyone explain reason behind this? FYI : The above method is
> > perfectly working without any compile / runtime error!
>
> > Thanks,
> > Harit- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Flex
India Community" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/flex_india?hl=en
-~----------~----~----~----~------~----~------~--~---