JS Days 2025 is now live – Join 5,000+ devs for the premier virtual JavaScript event. Register Now

Taking a look at the new Sencha SOAP Data Proxy

September 27, 2012 2276 Views
Show

Introduction

soapThe Sencha data package offers a number of different proxies to connect your application to all kinds of data. With the release of Ext JS 4.1.2 in Sencha Complete: Team, developers can now point to SOAP web services. With SOAP being one of the most popular web service protocols out there, this will allow developers a new option for connecting their applications to data.

The SOAP proxy works just like the other proxies, all you need to do is configure the proxy on your store, and you don’t have to worry about the details of handling the communication requests.

What is SOAP

SOAP (Simple Object Access Protocol) is an XML-based protocol that allows applications to communicate with remote web services. SOAP has a number of advantages. It’s protocol-independent, meaning you can transport SOAP messages over HTTP, SMTP or JMS. It also provides a strict contract that any client is required to follow in terms of object and method communication. However, due to it’s strict contract rules, it’s a bit slower when compared to using other communication protocols such as REST. The functionality in a SOAP service is defined in a Web Services Description Language (WSDL) file. It will show clients what methods and datatypes it’s expecting, so you can develop for that contract.

SOAP clients interact with the service by passing around a SOAP envelope, which is a specially formatted XML document. The envelope consists of an optional header, to pass application specific information with the request, and a required body that contains the information specific to the request. Below is a sample request showing the different envelopes used for the request and response of a simple service named getPeople and the returning Person objects.

Sample Request:



Sample Response:



Kevin
1
Kazmierczak



Sample Application

To try out the new SOAP proxy, I built a sample CRUD application that communicates with a ColdFusion web service I’ve created using a ColdFusion Component (CFC). ColdFusion provides a really simple way to generate the SOAP WSDL file for you by just marking your CFC methods as access “remote”.

The application shows a simple grid of data provided via the SOAP proxy. You can double click on a record to edit or delete it. There is a plus button in the top right to insert new records. During all of these interactions, I recommend you have a tool like the Chrome developer tools or Firebug running which will allow you to view the network requests, so you can see whats going on behind the scenes.

Server Setup

I’ve setup the server using ColdFusion 10 deployed on an Apache Tomcat 7 server. Inside the ColdFusion application container, I’ve created a CFC with 4 remote methods that are used to create, read, update, and delete a simple ‘Person’ object. The service is just working with mock data that gets reset on the next use, but works for demonstration purposes.

Data Setup

The model object is a very simple Person object consisting of a few basic properties.

Ext.define(‘SampleApp.model.Person’, {
extend: ‘Ext.data.Model’,
fields: [
{
name: ‘id’,
type: ‘int’
},
{
name: ‘firstName’,
type: ‘string’
},
{
name: ‘lastName’,
type: ‘string’
}
] });

Where things get specific to the SOAP proxy is inside the Store object:

Ext.define(‘SampleApp.store.People’, {
extend:’Ext.data.Store’,
model:’SampleApp.model.Person’,
autoLoad:true,
proxy: {
type: ‘soap’,
url: ‘/cfusion/samples/People.cfc’,
api: {
create: ‘createPerson’,
read: ‘getPeople’,
update: ‘updatePerson’,
destroy: ‘deletePerson’
},
soapAction: {
create: ‘http://localhost:8080/cfusion/samples/People.cfc’,
read: ‘http://localhost:8080/cfusion/samples/People.cfc’,
update: ‘http://localhost:8080/cfusion/samples/People.cfc’,
destroy: ‘http://localhost:8080/cfusion/samples/People.cfc’
},
operationParam: ‘operation’,
targetNamespace: ‘http://samples/xsd’
reader: {
type: ‘soap’,
record: ‘ns|return’,
namespace: ‘ns’
}
}
});

There are a lot of options in there, so let’s take a closer look at what’s going on in there.

  • type: ‘soap’
    • Sets the proxy to use the new SOAP proxy.
  • url: ‘/cfusion/People.cfc’
    • Provides the base URL used for the api methods you define. Due to browser security policies, this URL must be on the same domain as your application. If you need to access remote SOAP services, you’ll need to do a custom setup like a server side proxy service.
  • api
    • You define the SOAP operations that correspond to the create, read, update, destroy built in store actions. You only need to define the methods you are planning to use.
  • soapAction
    • Defines the URLs used for each of the CRUD methods. The SOAP specification requires this information to be passed in the request header.
  • operationParam: ‘operation’
    • Defines the name of the parameter in your SOAP service that points to the operation used with the CRUD request.
  • targetNamespace: ‘http://samples/xsd’
    • The XML namespace used to construct the SOAP envelope. You’ll want this to match up with what is defined in the WSDL contract.
  • reader
    • Sets up the SOAP reader for this proxy and tells it what to use for the record object when it parses the SOAP response. Also required is the namespace to use when parsing the response.

Once you have the store and the model setup, all you need to do is create a view that points to your data. Below is a sample grid view that shows the data from the store and the model.

Ext.define(‘SampleApp.view.ListView’, {
extend:’Ext.grid.Panel’,
title: ‘Person List’,
alias: ‘widget.listView’,
store: ‘People’,
columns: [
{
text: ‘Id’,
flex: 1,
dataIndex: ‘id’
},
{
text: ‘First Name’,
flex: 1,
dataIndex: ‘firstName’
},
{
text: ‘Last Name’,
flex: 1,
dataIndex: ‘lastName’
}
],
tools: [{
type: ‘plus’
}] });

When you put all of that together, you’ll get a grid that looks like this:

Soap List

Configuration Options

There are a few other options with the SOAP proxy that aren’t used in this example but are extremely helpful. If the SOAP service you are communicating with requires envelope objects in a specific format that’s not being generated automatically with the proxy, you can override how it creates them using the XTemplate strings. The proxy exposes the ability to overwrite any of the CRUD message envelopes. Below are two examples of how to override the base envelope and read objects templates.

proxy: {

envelopeTpl: [
‘,
‘,
‘{[values.bodyTpl.apply(values)]}’,

],
readBodyTpl: [
‘,
‘<{operation} xmlns="{targetNamespace}">‘,
‘,
‘<{$}>{.}‘,
‘,
‘,

] }

Conclusion

The addition of the SOAP proxy makes it easy to connect your data stores to a whole new set of data. All of the options are there, so you can connect to existing SOAP services or new ones being built. Developers don’t need to worry about the details, all they need to do is configure the proxy and the framework takes care of the rest.

Resources
Sample Code

Recommended Articles

Guide to Estimating ROI When Switching From DIY Libraries to Full Software Development Platforms Like Ext JS

Teams started with Do It Yourself, or DIY, JavaScript tools like jQuery and Bootstrap. But those fall apart as projects scale. Scattered code, user interface…

Top Frameworks Developers Are Using for Custom Software Development in 2025

We’re seeing it more every year; teams aren’t settling for plug-and-play tools anymore. In healthcare, finance, logistics, and other data-heavy industries, there’s a clear shift.…

Meet Sencha AI Coding Companion: Your AI-Powered Assistant for Faster Ext JS Development

Building modern web applications should be exciting. But too often, developers find themselves buried in documentation, endlessly Googling framework quirks, or stuck solving the same…

Ext JS 7.9 & Rapid Ext JS V1.1 Have Arrived

The Sencha team is excited to announce the latest Ext JS version 7.9 and Rapid Ext JS 1.1 release – designed to accelerate development, enhance…

Top 10 JS Grid Customization Tips for a Better UI Experience

Grids are pretty much everywhere in web apps. Working with financial sheets, product details, or users? Then you’ve probably used a JavaScript grid. It makes…

Why Ext JS Framework is the Go-To Framework for Building Scalable and Data-Intensive Web Apps

Web apps are much more advanced now. They deal with large amounts of data and need to stay fast, even with many users. If you’re…

View More

Trusted by Top Developers: Learn how to enhance your development journey — for free

Get the latest newsletter keeping thousands of developers in the loop.

Loved by developers at