HTTPService in ActionScript
I'm writing a service call in Actionscript (httpservice) and
it doesnt seem to work as expected. I've looked around and haven't
found anything that really explains this seemingly simple task, but
some that come close. I'd appreciate some help.
I have a php call that will pass an XML data file.
First my imports:
import mx.events.*;
import mx.rpc.events.*;
NOTE: I cant seem to get mx.rpc.http.httpservice to import...
weird error occurs... anyone know why?
Next, my service call, which occurs in a for loop (that seems
to matter to the posts I've been reading):
var DBService:HTTPService = new HTTPService;
DBService.url = "
http://192.168.11.12/getdata.php?length=day";
var DB_data:Object = new Object();
DBService.send(DB_data);
Then I try to use the data:
var _newChart:LineChart = new LineChart;
_newChart.percentHeight = 92;
_newChart.percentWidth = 100;
_newChart.showDataTips = true;
_newChart.x = 0;
_newChart.y = 0;
_newChart.dataProvider = DB_data.lastResult.data.point;
_newPanel.addChild(_newChart);
I've tried using both the service call and the object as that
data provider, but it errors every time. Anyone have some
experience with this? Seems like thistype of thing would be a
fairly common tool, but I haven't seen it used.
Thanks.
Okay, so I've tried to simplfy my code (taking out for loops
for a proof of concept) and the graphs still don not populate...
My code is below:
public var obj:Object = new Object;
private function
useHTTPservice(param:Object,URL:String,result_fxn:Function=null,result_format:String="e4x "):void
var contact:HTTPService = new HTTPService();
contact.resultFormat = result_format;
contact.url = URL;
contact.method = "POST";
if (result_fxn != null ) {
contact.addEventListener("result", result_fxn);
contact.addEventListener("fault", httpFault);
contact.send(param);
private function dataReceived(evt:ResultEvent):void
obj = evt.result.data.point;
Alert.show("succss");
//_newChart.dataProvider = evt.result.data.point;
private function httpFault(evt:FaultEvent):void
Alert.show("fail");
private function configkiosk(event:ResultEvent):void
// sets up the base page
MainCanvas = new Canvas();
MainCanvas.id = "Main Canvas";
MainCanvas.width = 860;
MainCanvas.height = 800;
MainCanvas.setStyle("backgroundColor","white");
MainCanvas.setStyle("horizontalCenter","0");
MainCanvas.setStyle("verticalCenter","0");
this.addChild(MainCanvas);
var _newPanel:Panel = new Panel;
_newPanel.percentHeight = 100;
_newPanel.percentWidth = 100;
_newPanel.x = 0;
_newPanel.y = 0;
_newPanel.setStyle("borderStyle","none");
_newPanel.setStyle("horizontalAlign","center");
MainCanvas.addChild(_newPanel);
var _newChart:LineChart = new LineChart;
_newChart.percentHeight = 100;
_newChart.percentWidth = 100;
_newChart.showDataTips = true;
_newChart.x = 0;
_newChart.y = 0;
_newPanel.addChild(_newChart);
var DB_Connect:Object = new Object;
var URL:String = new String;
URL = "
http://192.168.11.12/getdata.php?length=day"
useHTTPservice(DB_Connect,URL,dataReceived);
//horizontal axis
_newChart.dataProvider = obj;
var _newSeries:Series = new Series;
var line:LineSeries = new LineSeries;
_newChart.addChild(_newSeries);
var lineStroke:Stroke = new Stroke();
lineStroke.color = 0xFF9900;
lineStroke.alpha = 1;
lineStroke.weight = 2;
line.setStyle("linestroke",lineStroke);
line.yField = "CO2_BDROOM";
_newSeries.addChild(line);
}
Similar Messages
-
How to use HTTPSERVICE in Actionscript project.
Hello all,
I am doing an actionscript project, I want to use httpservice to send a data to server . Is any one knows how to use httpservice in actionscript project?
thanxfollowing code may help:
import mx.rpc.http.HTTPService;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
private function callHTTPSERVIDE():void
var hs:HTTPService = new HTTPService();
hs.url = 'Server.php';
hs.addEventListener( ResultEvent.RESULT, resultHandler );
hs.addEventListener( FaultEvent.FAULT, faultHandler )
hs.send();
private function resultHandler( event:ResultEvent ):void
//handle your result here
private function faultHandler( event:FaultEvent ):void
// code for fault handling. -
Specify 'GET' parameters in HTTPService in ActionScript?
Hi,
I was wondering if there is a way to specify variables and values in Actionscript to send in an HTTPService. Say I wanted to send a request like:
http://mydomain.com/?user=test
In AS3, I have this:
private function init():void {
service = new HTTPService();
service.destination = "http://mydomain.com";
service.method = "GET";
service.addEventListener("result", httpResult);
service.addEventListener("fault", httpFault);
Is there a way to use a function to specify GET variables (user=test)? Because otherwise it become more cumbersome to keep changing the destination screen and worry about escaping variables, etc, etc.Yes, I see that. I just wasn't sure how to specify the parameters. I am trying this:
var params:Object = new Object();
params.user = "test";
service.send(params);
That seems to have done it (actually, I realized I need to set the 'url' property, not the 'destination' property as well)
So I can just call this 'send' with different parameters on the same object over and over right? Do people generally put logic in the eventlistener to differentiate the type of responses that come back, or is it more common to add different event listeners for each type of request? In case it's not obvious, I'm making a RESTful php server that can respond to various methods in the request, modeled after the flikr API. -
I'm new to flex (and actionscript really) and I am having a
problem with the program I'm writing.
My httpservice object is throwing a httpFault with a message
that says:
[MessagingError message='Destination 'the destination of an
xml file' either does not exist or the destination has no channels
defined (and the application does not define any default
channels.)']
I know the xml file exists... i've tried a few others as
well... honestly I don't know what the channel bit means (I've
looked a few things from google about the same error and didn't
have an understanding of what was being said)
I've attached my code, I am not sure what I am suppose to do.
I am trying to update a list with data stored in the
ArtistList class which is my model, the php file at
http://localhost/bearcube2/artists.php
outputs xml...I've also tried just plain xml files on the web and
locally, i get the same error message
I want to declare the httpService in actionscript and not the
mxml because I plan on having user input send more GET requests,
but I haven't gotten that far yet.
Sorry If I'm missing something simple, but I've been trying
to find what im doing wrong for a while and since I'm new to flex I
figure I just don't understand how to use something.
Thanks for any helpCan someone please help me understand this error maybe?
I would appreciate it
[MessagingError message='Destination 'the destination of an
xml file' either does not exist or the destination has no channels
defined (and the application does not define any default
channels.)']
what are channels? -
Post Variables Using Actionscript
Hi,
I have seen on the docs that we could write HTTPService in
Actionscript method. I have completed the entire section based on
the description of the method defined on the doc, but I am having
some issues defining the variables to pass to the actual service
(mx:request as in MXML).
I need to know the actual variable that gets passed to the
service, because I would like to reuse the information returned
from the service for further edits. Since this information is not
stored in the XML, I wonder if anyone can tell me what is wrong
with the syntax below? Currently, all I get is this error:
TypeError: Error #1009: Cannot access a property or method of
a null object reference.
Anything is appreciated."alice_data" <[email protected]> wrote in
message
news:ge9nf1$1ai$[email protected]..
> Hi, Amy:
>
> Sorry, but I think I am getting a little confused at
this point. I have
> removed
> var loader:URLLoader = new URLLoader();
> loader.addEventListener(Event.COMPLETE,
function(event:Event):void {
> trace("finished sending and loading: "+ loader.data);
> });
> loader.load(request);
> and ran the code again and received the same error as
before.
>
> Part of the problems with the error I have been getting
is that I have
> not
> defined my parameters correctly, but again I tried to
take the parameter
> definition from the following line, it tells me I need
one argument:
> <mx:Button
> label="Submit" id="mySubmitButton"
click="useHttpService()"/>. What should
> I
> put in the parenthesis?
>
> The doc I referred to is at
>
http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?co
>
ntext=LiveDocs_Book_Parts&file=dataservices_099_15.html, but I
think my
> main
> problem here is that I am not sure how to define the
variables and pass it
> to
> the actual service and have the variables be handled
internally through
> Actionscript. Or, is what I trying to accomplish here
not possible at all?
Try changing this:
private var request:HTTPService;
to
private var request: URLRequest;
I still think you're getting a lot of warnings you're
ignoring (check the
problems tab). You should have gotten a duplicate variable
definition for
what you had.
What you're trying to accomplish is possible, but you DO need
to pay
attention to the warnings and errors Flex is trying to tell
you about. They
are your friend. -
Hi,
I know how to call a HTTPService in actionscript as follow. I was wondering how to call HTTPService in Flex (not from actionscript).
post_submit_tn_service.send();
<mx:HTTPService id="myservice"
</mx:HTTPService>Hi,
Here is my problem.
Let's assume I have two mxml files.
The mxml file2 contains HTTPService which is called in a ViewStack from file1.
When ViewStack is set to file2 for the second time (to update datagride), createComplete in file2 is not being called. So, no HTTPService is called when ViewStack is set to file2 for the second time.
<!-- file1 -->
<mx:ViewStack id="vsMyStack" x="0" y="0" width="100%" height="100%" >
<mx:Canvas id="file1" label="Login" width="100%" height="100%">
</mx:Canvas>
<mx:TabNavigator id="viewstack1" width="100%" height="100%">
<views:file2 width="100%" height="100%"/>
<views:file3 width="100%" height="100%"/>
</mx:TabNavigator>
</mx:ViewStack>
<!-- file2 ->
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init();">
private function init():void
post_service.send();
<mx:HTTPService id="post_service"
url="http://localhost/prod-ar/webservices/get_day_of_year.php"
method="POST"
</mx:HTTPService>
</mx:VBox> -
Sending SOAPRequest in HttpService
Hi,
I am trying to call a HttpService in ActionScript. Here is my
code snippet,
var parameters:Object = {};
parameters["SOAPRequest"]="<![CDATA[<SOAPRequest><Execute
xmlns='urn:schemas-microsoft-com:xml-analysis'><Command><Statement>WITH
MEMBER Measures.SPEED_RANGE1 AS
'AGGREGATE({[DRIVING_SPEED].[102]:[DRIVING_SPEED].[124]})' MEMBER
Measures.SPEED_RANGE2 AS
'AGGREGATE({[DRIVING_SPEED].[125]:[DRIVING_SPEED].[135]})' MEMBER
Measures.SPEED_RANGE3 AS
'AGGREGATE({[DRIVING_SPEED].[136]:[DRIVING_SPEED].[212]})' select
{Measures.SPEED_RANGE1,Measures.SPEED_RANGE2,Measures.SPEED_RANGE3}
ON COLUMNS,
{[TIME].[2008].[9].[1],[TIME].[2008].[9].[2],[TIME].[2008].[9].[3],[TIME].[2008].[9].[4], [TIME].[2008].[9].[5]}
on ROWS FROM SPEED WHERE
[CLIENTS].[ExpTestJay]</Statement></Command></Execute>]</SOAPRequest>]>";
service = new HTTPService();
service.url = "10.40.13.154";
service.method = "POST";
service.addEventListener(ResultEvent.RESULT, httpResult);
service.addEventListener(FaultEvent.FAULT, httpFault);
service.send(parameters);
I am getting this error,
HTTP request error->Error: [IOErrorEvent type="ioError"
bubbles=false cancelable=false eventPhase=2 text="Error #2032"].
URL: 10.40.13.154
I was able to successfully do it through the
<mx:HttpService>
<mx:HTTPService id="httpService" url="
http://10.40.13.154:8080/mondrian/xmla.jsp"
method="POST" result="displayData(event)"
resultFormat="e4x">
<mx:request>
<SOAPRequest>
{query}
</SOAPRequest>
</mx:request>
</mx:HTTPService>
I am just wondering what am I missing when I call the
HttpService through the action script ?
Any sample of how to send a SOAPRequest in a HttpService call
using ActionScript will be appreciated.I figured out the issue of why the service is not called.
Basically the url needs to be the address of the jsp that process
the request wherein in the above snippet it was just the URL
Now I am getting a different error stating that the
SOAPRequest request parameter value is invalid.
Basically the value is taken as a String object address like
below,
[STDOUT] Parameter =SOAPRequest Value =
[Ljava.lang.String;@7d6a33
how can I pass the SOAPRequest correctly? -
Hi, I'm creating an Adobe Air Application.
Why does everytime I click a button which calls the HTTPService an ActionScript Error displays, it says
[RPC Fault faultString="Default decoder could not decode result" faultCode="Client.CouldNotDecode" faultDetail="null"]
at mx.rpc.http::HTTPService/http://www.adobe.com/2006/flex/mx/internal::processResult()[C:\autobuild\3.2.0\frameworks\ projects\rpc\src\mx\rpc\http\HTTPService.as:881]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[C:\autobuild\3.2.0\frameworks\ projects\rpc\src\mx\rpc\AbstractInvoker.as:188]
at mx.rpc::Responder/result()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responde r.as:43]
at mx.rpc::AsyncRequest/acknowledge()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\ AsyncRequest.as:74]
at DirectHTTPMessageResponder/completeHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\s rc\mx\messaging\channels\DirectHTTPChannel.as:403]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
This is my code
<mx:Button y="169" label="Save Project" horizontalCenter="-524" id="saveProj_btn" click="propProjhttp.send()" enabled="true"/>
After I click this Button it will call the HTTPService
<mx:HTTPService id="propProjhttp" url="propProj.php" useProxy="false" method="POST" showBusyCursor="true">
<mx:request xmlns="">
<projNameTI>
{projNameTI.text}
</projNameTI>
<locationTI>
{locationTI.text}
</locationTI>
<ownerTI>
{ownerTI.text}
</ownerTI>
<materialCostTI>
{materialCostTI.text}
</materialCostTI>
<contCostTI>
{contCostTI.text}
</contCostTI>
<laborCostTI>
{laborCostTI.text}
</laborCostTI>
<totalCostTI>
{totalCostTI.text}
</totalCostTI>
</mx:request>
</mx:HTTPService>
Can someone please tell me how to solve this... thank you!How is the data returned formatted, as XML? If so is it well formatted? Perhaps you need to use the HTTPService resultFormat property, setting it to e4x for XML return data or to something else if the data returned is not XML.
If this post answers your question or helps, please mark it as such.
Greg Lafrance
www.ChikaraDev.com
Flex Development, Training, and Support Services -
Here is some code to show you how to use mxml HTTPService and
Actionscript's HTTPService side by side.
Goes over some basics that other beginners might appreciate.
<?xml version="1.0" encoding="utf-8"?>
<!--
Author: Travis Somerville
My first Actionscript application. Wanted to share a few
details with other people.
Subjects: HTTPService caching, making URL requests,
databinding parsed results, URL tutorial
This app shows the following:
* how to get URL requests and parse a complex response into a
useable value.
* the concept of avoiding caching is shown.
* the concept of how to import the HTTPService object when
using both mxml and Actionscript references.
* how to attach an event to an mxml HTTPService object, and
an Actionscript HTTPService object
* how to databind the HTTPService result to the parsed value
-->
<mx:Application layout="vertical"
xmlns:mx="
http://www.adobe.com/2006/mxml"
xmlns:remoting="com.oreilly.programmingflex.rpc.*"
initialize="initializeHandler(event)">
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.messaging.messages.HTTPRequestMessage;
//import mx.rpc.http.HTTPService;
import mx.rpc.http.mxml.HTTPService;
import mx.controls.Alert;
[Bindable] public var time:String;
[Bindable] public var timeServ2:HTTPService = new
HTTPService();
private function initializeHandler(event:Event):void {
timeServ2.resultFormat = "text";
// This URL updates our request with current time. Visit it
in your browser to see what we're parsing.
timeServ2.url = "
http://tycho.usno.navy.mil/cgi-bin/timer.pl?"
timeServ2.addEventListener(ResultEvent.RESULT,
timeResultHandler);
timeServ2.send();
// This handler shows how to parse copmlex responses.
// Useful for when the URL you want doesn't return just what
you need.
// Most likely to encounter a need when you're not
controlling the other end...
private function timeResultHandler(event:Event):void {
var timeResult:String = String(timeServ2.lastResult);
var timeZones:Array = timeResult.split("<BR>");
// The 3 means the 4th element in the array. This should
give Central Time.
time = timeZones[3];
private function timeResultHandler3(event:Event):void {
var timeResult:String = String(timeServ3.lastResult);
var timeZones:Array = timeResult.split("<BR>");
// The 4 means the 5th element in the array. This should
give Mountain Time.
time = timeZones[4];
]]>
</mx:Script>
<!-- Note how the URL has a ? on the end. For some
reason, this causes the request NOT to cache
A random number attached on the end might do the same thing.
Took me hours to figure this out! -->
<mx:HTTPService url="
http://tycho.usno.navy.mil/cgi-bin/timer.pl?"
id="timeServ3"
resultFormat="text"
result="timeResultHandler3(event)"
/>
<mx:Panel width="644" height="429" layout="absolute"
id="mainPanel" title="slide test" horizontalAlign="center">
<!-- Just another quick example of binding data to
something -->
<mx:Label text="{slider.value}" x="201" y="10"/>
<!-- the text="{time}" is where the databind magic
happens -->
<mx:TextArea id="textArea" text="{time}" x="10" y="54"
width="272" height="130"/>
<mx:HSlider id="slider" minimum="0" maximum="100"
snapInterval="2" enabled="true" x="10" y="10"/>
<mx:Button x="303" y="8" label="Get Time2"
click="timeServ2.send()"/>
<mx:Button x="437" y="8" label="Get Time3"
click="timeServ3.send()"/>
</mx:Panel>
</mx:Application>That is a good example. One recommendation: Do not use
lastResult in the handler, like this:
var timeResult:String = String(timeServ2.lastResult);
lastResult is intended for binding expressions.
Instead, declare the handler's event argument as a
ResultEvent (that is what it really is, remember to import
mx.rpc.events.ResultEvent), then use the event.result:
private function timeResultHandler(event:ResultEvent):void {
var timeResult:String = String(event.result);
Tracy -
HTTPService sending parameters
Hi,
I am looking for a way to send in a list of parameters to my
JSP. I already know how to use <mx:Request> tag, but it only
allows for a predefined number of parameters (at design time). What
i want to do is to send in an x number of parameters in, basically,
send in an XMLList contents as parameter list.
The documentation on HTTPService has a method xmlEncode() and
xmlDecode(). I could not get it to work and there aren't any
working examples out there. I guess i could serialize an XMLList
into a xml string myself and send it as one parameter field and
then parse it in jsp... or use JSON.
Is there a workable design pattern for sending complex
objects in?
If i was to use HTTPService in ActionScript, theoretically i
could dynamically add parameters to the Request object. I just
don't know how to create and use HTTPService fom AS... can someone
show me? is it hs:HTTPService = new HTTPService();
hs.request.add("key", "value"); ??
Thanks for any help.I personaly don't agree what they do in that example you
showed (
http://www.adobe.com/devnet/flex/articles/complex_data_02.html),
that is way too much extra unnecessary fanciness that adds
additional layer of logic on both sides, flex and jsp,which does
not really give any justifiable FLEXIbility to developer
why would you want to generate xml then on server side parse
xml when you can just as easily build request parametes on flex
side iteratively and same thing on jsp (with existing servler/jsp
API ) Exaple : iterate through all or partial request parameters
with code something like this :
for (java.util.Enumeration e = request.getParameterNames();
e.hasMoreElements() ;) {
String name = (String) e.nextElement();
String value = request.getParameter(name); -
Hey Just wondering if its possible to use actionscript variables for a HTTPservice, [not having to use httpservice via actionscript]
eg
<mx:HTTPService id="req" showBusyCursor="true" method="POST" url="http://localhost/flex1/add.php" useProxy="false">
<mx:request xmlns="">
<day>{dates.selectedDate.getDate()}</day> //instead of this have something like <day>{day.value}</day> ??????
<month>{dates.selectedDate.getMonth()}</month>
<year>{dates.selectedDate.getFullYear()}</year>
</mx:request>
</mx:HTTPService>
<mx:Script>
<![CDATA[
[Bindable] private var dateString:String;
public var day:int;
public var month:int;
public var year:int;
public function onClick():void
day = dates.selectedDate.date;
month = dates.selectedDate.month;
year = dates.selectedDate.getFullYear();
]]>
</mx:Script>
<mx:DateChooser id="dates" x="25" y="26" width="221" height="208" allowMultipleSelection="true" showToday="true" change="onClick()"/>Are you getting an error? Maybe you just need to make the other variables Bindable?
If this post answers your question or helps, please mark it as such.
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
[Bindable] public var day:int;
[Bindable] public var month:int;
[Bindable] public var year:int;
public function onClick():void{
day = dates.selectedDate.date;
month = dates.selectedDate.month;
year = dates.selectedDate.getFullYear()
]]>
</mx:Script>
<mx:DateChooser id="dates" x="25" y="26" width="221" height="208"
allowMultipleSelection="true" showToday="true" change="onClick()"/>
<mx:TextArea id="txt" text="{dates.selectedDate.getDate() + ' ' + dates.selectedDate.getMonth() + ' ' + dates.selectedDate.getFullYear()}"/>
</mx:Application> -
Revision: 949
Author: [email protected]
Date: 2008-03-27 07:12:59 -0700 (Thu, 27 Mar 2008)
Log Message:
Bug: BLZ-96 - When sending a HttpService request from ActionScript with multiple headers with the same name, it causes a ClassCastException in the server
QA: Yes - try again with legacy-collection true and false.
Doc: No
Checkintests: Pass
Details: Another try in fixing this bug. When legacy-collection is false, Actionscript Array on the client becomes Java Array on the server and my fix yesterday assumed this case. However, when legacy-collection is true, Actionscript Array becomes Java ArrayList on the server. So added code to handle this case.
Ticket Links:
http://bugs.adobe.com/jira/browse/BLZ-96
Modified Paths:
blazeds/branches/3.0.x/modules/proxy/src/java/flex/messaging/services/http/proxy/RequestF ilter.javaHi all!
Just to post the solution to this if anyone ever runs accross this thread...
For some reason i had it bad the first time, don't have time right now to see why but here is what worked for me:
HashMap primaryFile = new HashMap();
primaryFile.put("fileContent", bFile);
primaryFile.put("fileName", uploadedFile.getFilename());
operationBinding.getParamsMap().put("primaryFile", primaryFile);
HashMap customDocMetadata = new HashMap();
HashMap [] properties = new HashMap[1];
HashMap customMetadataPropertyRoom = new HashMap();
customMetadataPropertyRoom.put("name", "xRoom");
customMetadataPropertyRoom.put("value", "SOME ROOM");
properties[0] = customMetadataPropertyRoom;
customDocMetadata.put("property", properties);
operationBinding.getParamsMap().put("CustomDocMetaData", customDocMetadata);
Basically an unbounded wsdl type is an array of objects (HashMaps), makes sense, i thought i had it like this before, must have messed up somewhere...
Good luck all! -
Revision: 931
Author: [email protected]
Date: 2008-03-26 11:31:01 -0700 (Wed, 26 Mar 2008)
Log Message:
Bug: BLZ-96 - When sending a HttpService request from ActionScript with multiple headers with the same name, it causes a ClassCastException in the server
QA: Yes - we need automated tests for this basic case.
Doc: No
Checkintests: Pass
Details: RequestFilter was not handling multiple headers with the same name properly.
Ticket Links:
http://bugs.adobe.com/jira/browse/BLZ-96
Modified Paths:
blazeds/branches/3.0.x/modules/proxy/src/java/flex/messaging/services/http/proxy/RequestF ilter.javaHi all!
Just to post the solution to this if anyone ever runs accross this thread...
For some reason i had it bad the first time, don't have time right now to see why but here is what worked for me:
HashMap primaryFile = new HashMap();
primaryFile.put("fileContent", bFile);
primaryFile.put("fileName", uploadedFile.getFilename());
operationBinding.getParamsMap().put("primaryFile", primaryFile);
HashMap customDocMetadata = new HashMap();
HashMap [] properties = new HashMap[1];
HashMap customMetadataPropertyRoom = new HashMap();
customMetadataPropertyRoom.put("name", "xRoom");
customMetadataPropertyRoom.put("value", "SOME ROOM");
properties[0] = customMetadataPropertyRoom;
customDocMetadata.put("property", properties);
operationBinding.getParamsMap().put("CustomDocMetaData", customDocMetadata);
Basically an unbounded wsdl type is an array of objects (HashMaps), makes sense, i thought i had it like this before, must have messed up somewhere...
Good luck all! -
How to send results to actionscript using java via HttpService
Hi,
I do RPC using HttpService.
In my situation, I need to send results from Java code to
Flex Action script. I have defined a Java Servlet receiving data
from Flex application, then it processes with the data, finally the
Servlet is supposed to send some feedbacks to the client(Flex).
My question is that how can I define codes in doPost() method
that the following function will get "result" from the Java side.
public static function httpResult(event:ResultEvent):void
var result:Object = event.result;
//Do something with the result.
if (result.toString() == "success")
resultMessage.text = "Login Success";
resultMessage.text = "Invalid User";
}I advise having your servlet build an xml string, maybe put a
status attribute in the root tag, like this:
<myroot status="success">
<mytext>Some text</mytext>
</myroot>
and return that to the calling Flex client. XML is easier to
work with than Object. On the HTTPService tag, set
resultFormat="e4x", and it will return plain XML.
then in the handler, do:
var xmlResult:XML = XML(event.result); //this will already be
the myroot node
//Do something with the result.
if (xmlResult.@status== "success") //reads the status
attribute
resultMessage.text = xmlResult.mytext.text(); //get the
value of themytext text() node
resultMessage.text = "Error";
Tracy -
How to send JSON data in HTTPService to PHP web service question
I'm using Flex 4 and a mx:HTTPService to send a JSON request to a php web service. I'm not sure if I'm sending the request correctly. Could someone look at the code below to see what I'm doing wrong?
thanks
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark"
width="100%" height="100%">
<fx:Declarations>
<mx:HTTPService id="service" url="https://my web service url/"
method="POST" resultFormat="text" result="onResult(event)" fault="onFault(event)">
</mx:HTTPService>
</fx:Declarations>
<fx:Script>
<![CDATA[
import com.adobe.serialization.json.JSON;
import mx.collections.ArrayCollection;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.utils.Base64Encoder;
[Bindable]private var username:String = "[email protected]";
[Bindable]private var password:String = "the password";
[Bindable]private var accountNumber:String = "49055";
[Bindable]private var anticipatedDeliveryDate:Number = 20101115;
[Bindable]private var purchaseOrder:String = "#123 for retailer";
[Bindable]private var detailRecords:Array = new Array();
[Bindable]private var key:String = "abc123";
private function populateService():void {
populateProducts();
setRequestHeader();
setRequestData();
service.send();
private function setRequestHeader():void {
var encoder:Base64Encoder = new Base64Encoder();
encoder.insertNewLines = false;
encoder.encode(key);
service.headers["Authorization"] = "VIP " + key;
service.headers["Content-Type"] = "application/json";
private function setRequestData():void {
service.request.username = username;
service.request.password = password;
service.request.accountNumber = accountNumber;
service.request.anticipatedDeliveryDate = anticipatedDeliveryDate;
service.request.purchaseOrder = purchaseOrder;
service.request.detailRecords = detailRecords;
// caching test
var rnd : Number = Math.round(Math.random()*1000);
service.request.cacheOff = rnd;
private function populateProducts():void {
var prod1:Object = new Object();
prod1.itemCodeOrUPC = "00241";
prod1.itemDescription = "Budweiser Keg 1/2 BBL";
prod1.quantityOrdered = 2;
prod1.orderUOM = "Keg";
var prod2:Object = new Object();
prod2.itemCodeOrUPC = "00219";
prod2.itemDescription = "Budweiser 24/12 OZ CAN";
prod2.quantityOrdered = 4;
prod2.orderUOM = "Case";
detailRecords.push(prod1);
detailRecords.push(prod2);
private function onResult(event:ResultEvent):void
var json:Object = JSON.decode(event.result as String);
private function onFault(event:FaultEvent):void
trace("Fault: " + event.fault.faultString);
]]>
</fx:Script>
<mx:Panel width="95%" height="100%" color="#000000">
<mx:HBox width="100%">
<mx:Button label="Submit" click="{populateService()}"/>
</mx:HBox>
</mx:Panel>
</s:Application>Have you think abut using ActionScript in your Flex application? Or, you can write javascript to be proxy between your flash app and backend PHP web service?
Also, it seems that you will allow every customer's flash player to have a copy of secret code. I think it is dangerous design because an flv file can be easity decompiled. Therefore, you secret code can be found if it is not input by your end user and it is populated on your serverside script.
Maybe you are looking for
-
ERROR 7 WINDOWS ERROR 193 INSTALLING LATEST ITUNES PC
Getting error 7 windows error 193 missing or invalid odbc32.dll, get after installing and when open itunes. The itunes installing is the lastest from alpple. os is vista 64 and running itunes 64 installer. Have ran checkdsk and sfc and no problem in
-
80Gb classic cant be seen by itunes
When ever i connect my 80 gb classic ipod to my computer i get a message that pops up that is titled: devicemsglistenerwnd: iPod Service.exe – Application error and in the message box it says: the instruction at "0x00427259" referenced memory at "0x0
-
Is there any java Charset for converting EBCDIC packed decimal to ASCII?
Pls reply if you know the solution.
-
Hi Experts, Could someone please help me with this scenario. We are using orders 01 to create PO on vendor and the receiving plant is the sending partner number. The requirement is as below. PO to be created on a Plant 1000 and the goods to be deli
-
Satellite A500 - Display driver stopped responding
Hi, 3 weeks ago I bought brand new Toshiba A500. I post here because I didn't find any helpful solution. Here is specification: Processor: intel core i3 M330 2.13GHz Graphic: NVIDIA GeForce GT 330M (1024 MB) Hard drive: MJA2320BH G2 (320 GB, 5400 RPM