Page 1 of 1

best way to call a CFML webservice

Posted: Thu May 25, 2006 2:17 pm
by sweetp123
I have been reading through the forum and am a little confused about how to go about calling a ColdFusion web service from one of my pages.

let's say my webservice is at:
http://www.mysite.com/components/mywebservice.cfc?wsdl

I want to pass in one variable (a PIN that the user has entered) and the function mywebservice returns a string containing the accountID or the user if it is valid and an empty string if it is not.

I know i need to call it as method POST because i am sending a variable but where is my return value (the string) going to be located? should i use submit, data or subdialog?

Thanks!

Use data tag or subdialog call so control is returned to IVR

Posted: Fri May 26, 2006 4:54 pm
by support
Hi,

You'll probably want to use either the IVR tag, <data>, or a subdialog call; this way, control is returned to the IVR at the appropriate place in the IVR call flow.

Here is an (untested, so caveat emptor) IVR example of doing this with a subdialog call:

<form id="callWebService">
<subdialog name="getAccountID" src="getAccountID.vxml" namelist="PIN" method="post"> <!-- PIN is declared and assign somewhere else -->
<filled>
<if cond="getAccountID.accountID == ''">
oh, no... we got an empty string
<else />
we didn't get any empty string... let's do something interesting
</if>
</filled>
</subdialog>
</form>

In getAccountID.vxml, you'll have some scripting (ColdFusion, PHP, ASP, whatver) that accepts the POSTed PIN variable and does something with it. At the end of this document, you'll need a simple form that returns one or more variables using the IVR tag, <return>, (below example is PHP):

<?php

$PIN = $_POST['PIN'];
$accountID = call_web_service($PIN);

?>

<vxml>
<form id="returnAccountID">
<block>
<var name="accountID" expr="'<?= $accountID ?>'" />
<return namelist="accountID" />
</block>
</form>
</vxml>


Hope this helps,

Plum Support

Posted: Fri May 26, 2006 11:33 pm
by sweetp123
ok thanks i'll try this once i get my application setup properly as i am just using the scratchpad for now.
where does the verifyPIN.vxml file reside? on my own server?
so it's not really calling a web service then - just a page that is posted to remotely?
and how will it be executed properly by my cold fusion server if the extension is vxml...???
sorry for all the questions - i'm new to this and just trying to get my head around it :oops:

Posted: Fri May 26, 2006 11:34 pm
by sweetp123
sorry i meant the getaccountID.vxml file - where will it reside?

IVR script

Posted: Tue May 30, 2006 10:03 am
by support
The getaccountID.vxml file will reside on your own IVR server. It doesn't have to have the .vxml extension. It could be .cfm or .php or .asp or whatever's necessary for your IVR application server to execute the IVR script.

As far as whether it's a web service -- by definition, any IVR script that accepts POST parameters from another script and responds with data, XML-formatted or not, is a web service. So a "page that is posted to remotely" is definitely a web-service since it responds to requests via HTTP with raw data in a format that can be parsed by the requesting IVR application.

Posted: Mon Jun 05, 2006 10:52 am
by sweetp123
i got it working :D

for future reference for other coldfusion developers:
i finally realized why i was having so many problems - coldfusion adds a ton of whitespace to the beginning of pages mainly due to the Application.cfm page that is processed - so i used cfsilent tags around all of my code - including the Application file and also the cfprocessingdirective suppresswhitespace = yes as well as the cfsetting tag to enable cfoutput only.

the returned page was then recognized as a proper xml file...
thanks for your help - the last call log file pages made a huge difference in debugging the code