Hub Nexus
Updated

AuthorNo author yetClaim it

See something to improve? Propose a change.

Support

Web services can be called directly from an XForms application using the submission element in the model.

Connecting a web service to an Event

To call a web service you first need to "wire it" up to an event. For example this can be a "submit" button at the end of a form.

The submit element is usually in the presentation (inside the body tag) and is wired to a element in the model.

id="my-model">
id="callWebService">
<...>

submission="callWebService">
Press Button to Call a Web Service

</

== Sample Program ==
The program consists of several parts.

In the model:

The SOAP response placeholder

=== SOAP input message ===
Here is an example of the input SOAP message

id="submit-instance" xmlns="http://schemas.xmlsoap.org/soap/envelope/">;

xmlns:m="http://www.example.com/web-services/my-operation"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">;
xsi:type="xsd:string">Hello world!

=== Putting the SOAP Results in an Instance ===
When the web service returns you need to put the returning SOAP response in an instance. We create another instance in the model and we also need to give it an identifier. In this case I called it "results-instance".

lang="xml">
id="results-instance" xmlns="">

id="results-bind" nodeset="instance('results-instance')/env:Envelope"/>

This is just a temporary storage area that the results will be inserted into.

The XForms submission Statement

id="send-to-dor-document-web-service"
action="http://www.example.com/web-service/my-web-service"
method="post"
mediatype="text/xml"
ref="instance('submit-instance')"
replace="instance"
instance="results-instance">
case="case-busy" ev:event="xforms-submit" />
case="case-submit-error" ev:event="xforms-submit-error" />
case="case-done" ev:event="xforms-submit-done" />

There are few things to note. The action attribute is the URL of the connection point of the web service. The operation you call is not included in the URL.

The method (get, put or post) in this case is a post.

Mediatype

XForms is a rich application development standard. So by default the HTTP transactions used by XForms use a mediatype for XML application that includes binary files and binary attachments. So by default, XForms sends an HTTP command with the following in it:

mediatype="application/xml"

However most simple web services do not support binary. The mediatype for ASCII text (without binary) is just:

mediatype="text/xml"

So if you will also be sending binary files you will need to add a mediatype attribute to to your submission:

**

Debugging Response Documents

You can also replace the entire document with the XML result (the option is replace="all") or you can just have it replace an instance.

The last three statements are for displaying results.

A style sheet

This makes the error messages red and the correct responses green.

@namespace xf url("http://www.w3.org/2002/xforms");
body {font-family: Helvetica, sans-serif}
.code {font-family: Courier New, fixed-width; font-weight:bold;}
.error-message {font-weight:bold; color: red}
.ok {font-weight:bold; color: green}
xf|output {font-weight:bold; font-size: 16pt}

The Presentation

Here is the actual body of the XForms document. It has a single button that calls the web service.

Web Service Demo
Note: With some browsers (FireFox) you must add the appropriate
hosts to your XForms "white list" for this application to run.
With FireFox see Tools/Options/Content tab.

Call Web Service

Current form status:

Status: Ready to call web service.
Waiting for response...please stand by...

Submission error. Did you remember to allow XForms to submit data to other domains?

Results returned successfully

Return value:

Discussion

The presentation conditionally displays the error messages using a switch/case section. The toggle elements are each triggered by the appropriate event.

You can also put a spinning GIF icon in the section to get an animation for a response from the server.

Where this page came from

This page was imported from Wikibooks. From “XForms” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

In these publicationsXForms

LanguagesEnglish

Licence: CC BY-SA 4.0 · Adapted from en.wikibooks.org

1

0

0

0

Spinner Logo

Comments

Spinner Logo
Version: 2CC0 1.0 — public domain
The runaway star that left the Tarantula Nebula
Version: 2CC0 1.0 — public domain
The Blackwell School, where segregation had no law behind it
Version: 2CC0 1.0 — public domain
The Eagle Nebula, seen in the infrared
Version: 2CC0 1.0 — public domain
The house where the Equal Rights Amendment was written
Version: 2CC0 1.0 — public domain
The Aleutians, the forgotten front of the Second World War
Version: 2CC0 1.0 — public domain
The Cosmic Cliffs are not cliffs