Skip to main content
Participant
July 11, 2008
Question

ColdFusion Script not work with Httpservice

  • July 11, 2008
  • 2 replies
  • 444 views
At first I use PHP to generate xml output on page then use the data to my httpservice with resultformat e4x. Everything is fine. But now I want to use coldfusion script since I'm planning to use ColdFusion as my web server. I have this script located on my server and generate the data in XML file then the XML file is used in my web, loaded through httpservice.

My PHP code was like this :

<?php

define( "DATABASE_SERVER", "localhost" );

define( "DATABASE_USERNAME", "root" );

define( "DATABASE_PASSWORD", "" );

define( "DATABASE_NAME", "MyCinema" );


$mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error());

mysql_select_db( DATABASE_NAME );

$Query = "SELECT * FROM film";

$Result = mysql_query( $Query );

$Return = "<movies>";

while ( $film = mysql_fetch_object( $Result ) )
{
$Return .= "<film><judul>".$film->JUDUL.
"</judul><deskripsi>".$film->DESKRIPSI.
"</deskripsi><genre>".$film->GENRE.
"</genre><produser>".$film->PRODUSER.
"</produser><produksi>".$film->PRODUKSI.
"</produksi><homepage>".$film->HOMEPAGE.
"</homepage><durasi>".$film->DURASI.
"</durasi><url>".$film->URL."</url></film>";
}

$Return .= "</movies>";

mysql_free_result( $Result );

print ($Return);

?>

And now I try to get the same result using coldfusion script. At first I dont write the XML to file, I just cfoutput it just like I do with PHP just print result but it doesnt work out with my HTTPservice. Until I try to write it to XML file then coding my httpservice to read directly from that XML file. here is my coldfusion code.

<cfcomponent>
<cffunction name="a" returnType="Void" output="true" access="remote">
<cfprocessingdirective suppresswhitespace="Yes">
<cfquery name="GetFilm" datasource="myCinemaData">
SELECT b.* FROM playing a, film b
WHERE a.kode_film=b.kode_film AND a.start > <cfqueryPARAM value = "#DateFormat(Now())#"
CFSQLType = "CF_SQL_STRING">
</cfquery>
<cfxml variable="userXML">
<movies>
<cfloop query="GetFilm">
<cfoutput>
<film>
<judul>#GetFilm.JUDUL#</judul>
<deskripsi>#GetFilm.DESKRIPSI#</deskripsi>
<genre>#GetFilm.GENRE#</genre>
<produser>#GetFilm.PRODUSER#</produser>
<produksi>#GetFilm.PRODUKSI#</produksi>
<homepage>#GetFilm.HOMEPAGE#</homepage>
<durasi>#GetFilm.DURASI#</durasi>
<url>#GetFilm.URL#</url>
</film>
</cfoutput>
</cfloop>
</movies>
</cfxml>
</cfprocessingdirective>
<cffile action="write" file="#expandPath(".")#\userXML.xml" output="#userXML#">
</cffunction>
</cfcomponent>

Because I need to create the XML files first I try to execute this coldfusion script first using webservice before I execute my Httpservice but the XML file creation is slower than the execution of my httpservice afterthat so it shows an error that my XML file isn't not available. What can i do? I've tried to show the output using cfoutput and run that script directly on my httpservice just like the way I use print result on PHP but it produce an error.
This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
July 13, 2008
... I try to execute this coldfusion script first using
webservice before I execute my Httpservice but the
XML file creation is slower than the execution of
my httpservice afterthat so it shows an error
that my XML file isn't not available.


Then it might help to apply a named lock to ensure that the Httpservice runs only after the web service call is complete. For example, apply an exclusive named lock on the code that calls the web service and a readonly lock of the same name to the Coldfusion code that interacts with the Httpservice.

Inspiring
July 12, 2008
Is it outputting the XML file? Try running your CF code all by itself outside of a cfc and see what it does.
Participant
July 12, 2008
I've tried with other cfc source that also generate XML and I've tried to run it directly to know the result and the XML is fine. The page on my browser showed a normal and good XML but when I try to call it from my flex httpservice it shows stream error. I don't get it.