PDA

View Full Version : flash remoting 2 and Amazon web services


sigh
07-12-2005, 08:14 PM
I'm trying to access Amazon's web service (either AWS 3.0 or ECS 4.0)
through Flash Remoting 2.0 components and PHP/nusoap gateway.

I have simple actionscript code, which successfully calls a web
service through the wsdl file; however, when I use the same code and
try to call one of Amazon's web services, I am unsuccessful.

My question is: what is wrong with my code? I've included below my
code (call to method ItemLookup), related links, and various other,
perhaps pertinent, information. Please no links to tutorials, as I have gone through most of them already.

import mx.remoting.Service;
import mx.remoting.PendingCall;
import mx.rpc.RelayResponder;
import mx.rpc.FaultEvent;
import mx.rpc.ResultEvent;
mx.remoting.debug.NetDebug.initialize();
mx.remoting.debug.NetDebug.trace();

var flashService:Service = new Service(
"http://[website].com/flashservices/gateway.php",
null,
"http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl",
null,
null);

var parameters = new Object();
parameters.Service = "AWSECommerceService";
parameters.SubscriptionId = "[20 digit SubscriptionId]";
parameters.Operation = "ItemLookup";
parameters.ItemId = "0393316041";

var pc:PendingCall = flashService.ItemLookup(parameters);
pc.responder = new RelayResponder(this, "amazonSearch_Result",
"amazonSearch_Fault");

function amazonSearch_Result(re:ResultEvent):Void{
trace (re.result.Items.ProductName);
}

function amazonSearch_Fault(fe:FaultEvent):Void{
trace (fe.fault.faultstring);
}


Link to Amazon's ECS:
http://www.amazon.com/gp/aws/sdk/102-6126594-2444162?v=2005%2d03%2d23&s=AWSEcommerceService


Other Info:
1) there is a gateway.php file on my server in the flashservices directory
2) nusoap files are included in the flashservices\lib directory
3) the web server runs PHP 4.?
4) using Flash MX 2004 Professional and Flash Remoting 2.0

Additionally, this is the error I receive from the NetConnection Debugger:

DebugId: "0"
EventType: "Result"
MovieUrl: "file:///C|/AmazonWCS.swf"
Protocol: "http"
Result: (boolean) false
Source: "Client"
Time: 1121194395922
Date (object #1)
....."Tue Jul 12 14:53:15 GMT-0400 2005"

or

Result (object #2)
.....detail: "The request contains an invalid SOAP body."
.....faultcode: "SOAP-ENV:Client"
.....faultstring: "We encountered an error at our end while processing
your request. Please try again"

madgett
07-14-2005, 02:14 AM
This will make testing calls easier, install this extension into dreamweaver:

http://www.communitymx.com/content/article.cfm?cid=A7EB3C45962FD5CA

It's written for ColdFusion, however it might work with PHP.

sigh
07-15-2005, 12:59 AM
I got the it to work in the extension above; however, it still doesn't work in my Flash file. However, I installed php5 and I think I'm getting closer.

Now in the netConnectionDebugger I get the following call:
MethodName: "http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl.ItemLookup"
Parameters (object #2)
.....[0] (object #3)
..........ItemId: "0393316041"
..........Operation: "ItemLookup"
..........Service: "AWSECommerceService"
..........SubscriptionId: "[mySubscriptionId]"

However, after the next Connect to my gateway file, I the Result part gives me the following error:

esult (object #2)
.....Items (object #3)
..........Request (object #4)
...............IsValid: "False"
...............Errors (object #5)
....................Error (object #6)
.........................[0] (object #7)
..............................Code: "AWS.MissingParameters"
..............................Message: "Your request is missing required parameters. Required parameters include SubscriptionId."
.........................[1] (object #8)
..............................Code: "AWS.MissingParameters"
..............................Message: "Your request is missing required parameters. Required parameters include SubscriptionId."
.........................[2] (object #9)
..............................Code: "AWS.MissingParameters"
..............................Message: "Your request is missing required parameters. Required parameters include ItemId."
.....OperationRequest (object #10)
..........RequestId: "00DHHA6S8ZX79PXVQHNZ"
..........RequestProcessingTime: 0.00590085983276367
..........Arguments (object #11)
...............Argument (object #12)
....................Name: "Service"
....................Value: "AWSECommerceService"
..........HTTPHeaders (object #13)
...............Header (object #14)
....................Name: "UserAgent"
....................Value: "PHP SOAP 0.1"

This is weird that it says I need to provide the correct parameters b/c as you can see in the call, they're their. Any thoughts?

madgett
07-15-2005, 11:18 AM
It looks as though Flash is not parsing the web service correctly. If it works in the extension and gives the right parameters then it should definitely be able to work in Flash.

You have put the remoting classes in the library of the Flash file right? You need to make sure that you've downloaded the remoting components from MM site.

You can get them here: http://www.macromedia.com/software/flashremoting/downloads/components/

Once you download and install them above to put them in your flash file go to Window -> Other Panels -> Common Libraries -> Remoting.

Then the library pops up and drag the classes into your fla library.

sigh
07-15-2005, 05:02 PM
Thanks for trying to help me through this.

Yes, I've placed the remoting classes in my library.

I'm able to consume other web services just fine, however, Amazon doesn't seem to work.

Here is the event description I receive in the NetConnection Debugger:

Result -{Items:[object Object], OperationRequest:[object Object]}

Is it possible that the error is coming through b/c I'm not handling the return result correctly?

Right now, attached the ResultEvent object to a data grid's dataProvider property; however, Amazon results maybe too complex for that type of assignment.

sigh
07-15-2005, 05:32 PM
Here's the error from my Apache error log. Can someone help me interpret this?

[Fri Jul 15 02:55:26 2005] [error] [client 127.0.0.1] PHP Warning: SoapClient::__construct(): I/O warning : failed to load HTTP resource in C:\\Program Files\\Apache Group\\Apache2\\htdocs\\flashservices\\actions\\We bServiceAction.php on line 131, referer: http://localhost/flashservices/gateway.php

[Fri Jul 15 02:55:26 2005] [error] [client 127.0.0.1] PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.amazon.com/onca/soap?Service=AWSECommerceService' in C:\\Program Files\\Apache Group\\Apache2\\htdocs\\flashservices\\actions\\We bServiceAction.php on line 131, referer: http://localhost/flashservices/gateway.php

nickolasnikolic
08-15-2005, 10:58 AM
To start, Flash is self-defeating when it comes to web-services.

Be sure to include the target url(s) from Amazon in your application's trusted sites list. Confer with MM documentation to clear up creating the XML file. Otherwise, only web services available from the originating server and exact domain of the flash file may be used.

Here is the Macromedia Article:
http://www.macromedia.com/devnet/flash/articles/fplayer_security.html

Lastly, your SOAP call will fail unless you also include the following:

XMLescaping with values None/Single/Double
Validate with values: True/False

XMLescaping tells Amazon if the data should be url encoded so you don't have to worry about it (most validators --- including the validator in Flash --- will often choke on Amazon data - mostly due to invalid xml --- user comments separating paragraphs with only a <p> with no ending tag, and so on.)

Validate tells Amazon only to respond with the validity of the request.

As a side-note, Flash is probably the last place that I would consider to use the AWS. Best would be a server-side implementation where you can actually attend to the requirements of AWS such as caching responses so that they are only pulled from Amazon once a second (their maximum) which won't work on the client-side (imagine 1000 users all requesting at once) as well as others.

The likely best implementation would be to build your request on the server-side in a language like PHP, ASP, or ColdFusion, then offer a local web service directly to your flash files, or an intermediary such as Javascript, then passing to Flash.

It is rather easy once you load the Amazon .wsdl to handle the web service in PHP5. One catch: watch out for multiple identical elements (i.e. two or more movie directors in the same part of the xml tree - which happens often within the AWS) because the resulting object in PHP will make these accessible as an array in the object rather than simply a property.

Second best is to make the needed requests through Javascript (or other client-side environment like a Java applet) and then pass that into Flash.

Worst is to have flash try to handle it alone, it probably won't work --- definitely won't always work due only to how much Amazon will send back as well as malformed xml. I can pretty much assure you that the each time you attempt a Large or Accessories Response Group from Amazon, flash will crash.

martom
09-26-2005, 02:30 PM
Hey!! Flash does not have any contact to XML files if you use Flash Remoting!
Flash sends all the data in binary format to the gateway on the server. the server does all the webservice calling and xml parsing and sends the result back to the flash player.
Please read the documentations about remoting on amfphp.org

Now... I have the same problem as sigh... same error messages! If you look at the examle on www.flash-remoting.com/notablog and check the transfers in your netConnectionDebugger you will realise that this example connects not direct to the wsdl file but to a coldfusion component on the flash-remoting.com server!