We've Moved! Please visit our new and improved forum over at our new portal: https://portal.plumvoice.com/hc/en-us/community/topics

How do I interact with a Web Service?

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
agfa
Posts: 40
Joined: Thu Jun 15, 2006 12:56 pm

How do I interact with a Web Service?

Post by agfa »

I am developing a webservice which my vxml pages call. Initially I started using the:
<submit next="service_name/method" method="post"/> notiation

I have since discovered that Plum parses the 'service/' notation and assumes that this refers to a sub-folder. The first call will work but any furthur submits will now have "service_name/" as part of the base url. Of course, this folder does not exist so I cannot move to furthur vxml scripts.

To get around this problem, I was informed that I could use the '../' notation in the submit tag, (e.g. <submit next="../testpage.vxml" method="post"/>), but this does not seem to work, (Plum cannot still seem to find the page although it is there and the address is valid).

Has anyone successfully interacted Plum vxml with a webservice? I have begun to assume that I cannot use the <submit> tag for this anymore; unless anyone has any other suggestions about what to do. Can I force Plum to use a specific base url?

Or, does anyone know how I can use the <data> tag to achieve this? I am new to vxml (and xml).

Any help would be much appreciated since I seem to have stalled.
Thank you.

Regards

Justin

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

IVR example that uses a static page, collects / submits id

Post by support »

Hello,

The script/method notation is not the correct approach for using the <submit> tag. The <data> tag is provided to avoid page transitions while still performing a synchronous GET or POST. The <data> tag will perform the server request and then expects to recieve any well formed XML in response. The XML response is parsed by the VoiceXML platform and then becomes available via a Javascript DOM object. Here is an IVR example that uses a static page, collects / submits id and pin data to a PHP script and then acts on the data returned in the DOM object:

index.vxml - This is the static vxml file.

Code: Select all

<?xml version="1.0"?>
<vxml version="2.0">
	<var name="id"/>
	<var name="pin"/>
	<form id="login">
		<field name="tmp_id" type="digits">
			<prompt>Please enter your I D</prompt>
			<filled><assign name="id" expr="tmp_id"/></filled>
		</field>
		<field name="tmp_pin" type="digits">
			<prompt>Please enter your pin</prompt>
			<filled><assign name="pin" expr="tmp_pin"/></filled>
		</field>
		<filled><goto next="#authenticate"/></filled>
	</form>
	<form id="authenticate">
		<data name="domAuth" src="auth.php" method="post" namelist="id pin"/>
		<block>
			<script>
				var rootnode = domAuth.documentElement;
				var status = rootnode.getAttribute('status');
			</script>
			<if cond="status == 'success'">
				<prompt>You have been successfully authenticated</prompt>
				<goto next="#main"/>
			<else/>
				<prompt>I'm sorry that is not a valid I D or pin</prompt>
				<goto next="#login"/>
			</if>
		</block>
	</form>
	<form id="main">
		<!-- remaining application code goes here -->
		<block>This is the main application</block>
	</form>
</vxml>
auth.php - This is the php code that returns a simple XML document to be parsed by the <data> tag.

Code: Select all

<?php
header("Content-type: text/xml");
$id = $_POST['id'];
$pin = $_POST['pin'];
// WE WOULD NORMALLY PERFORM THE AUTHENTICATION HERE
$status = "success";
echo("<?xml version=\"1.0\"?>\n");
echo("<auth id=\"$id\" pin=\"$pin\" status=\"$status\"/>");
?>
For more advanced XML parsing the reference for accessing the DOM via Javascript can be found in the VoiceXML 2.1 Specification. Hope this helps.

Regards,
Plum Support
Last edited by support on Wed Jan 13, 2010 2:31 pm, edited 2 times in total.

agfa
Posts: 40
Joined: Thu Jun 15, 2006 12:56 pm

Post by agfa »

Thanks for the advice, I appreciate the reply.

I struggled a little with the <data> tag approach, but then using the Plum and other vxml web sites, I think I found a good working approach. I have written a summary here for others who might interested.

The vxml code interacts directly with a DotNet WebService.

First declare a nice variable:
<var name="NiceName" expr="'WebService.asmx/Funcname'"/>

Then call the service using the variable:
<data name="domName" srcexpr="NiceName" namelist="var1 var2" method="post"/>

In my case, the web service returns a short, in memory xml document; this is attached to the "domName" variable.
I have some Javascript in a seperate file that extracts the value(s) I want, and returns them to the vxml using:
<var name="stringVal" expr="GetStringVal(domName)"/>

And that's it. From that moment I am back in the vxml and can work as usual. I am now attempting to use this approach all over the place.

Thanks again.

agfa
Posts: 40
Joined: Thu Jun 15, 2006 12:56 pm

Post by agfa »

I forgot to add, (just in case anybody does actually look here for help),

you have to ensure your webservice works with POST/GET statements; by default .Net 2003 is designed to work with SOAP messages only.

Change your web.config file to include:
<!-- WEB SERVICE REQUESTS -->
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>


under the <system.web> section.

agfa
Posts: 40
Joined: Thu Jun 15, 2006 12:56 pm

Post by agfa »

Something else I forgot to add, (from ages ago! Doh!)
These are simply notes to blow to help out anyone else who may be alive out there... Jack? Jack!

When passing variables into a Web Service, the variables in vxml must match the web service ones exactly. I.e. In name, (case-sensitive); in their specified order and in their type. Any mismatch will result in an error - bad fetch.
(At least in my experience anyway, you may be able to mix integers and strings, not sure.)
E.g. <data name="domWebService" srcexpr="wsLogon" namelist="sessionId userPin passWord" method="post"/>
The variables in the namelist here, must match exactly the variables declared in the webservice logon function.

Also, if your web-service function crashes internally, (for whatever reason) you will often end up with error - bad fetch.

Regards

Post Reply