Web Services is a fairly new technology that has become very popular in the past few years. Basically, a Web service is a service that is created to communicate, using standard XML formats, to any application that knows how to talk to it. The Web service will have a public interface written in Web Service Description Language (WSDL). The interface describes what the Web service does and how to communicate with it. The actual communication is done with XML, typically using the SOAP protocol. Because XML is basically just text, an application that can read text can read and interpret a Web service. Because of this, Web services can be created by one type of server and utilized by anyone who can read the XML.
ColdFusion MX has made working with Web services even easier by allowing the developer to interact with Web services by using traditional ColdFusion-style tags. Also, Dreamweaver MX can introspect these services in the Components panel, and it will automatically create the ColdFusion MX code necessary to utilize the services.
Community MX publishes a web service that will display information about the latest content available from the site. This service can be used by anyone who knows how to consume a web service. Content of Community MX is copyright © 2003 by Community MX and cannot be redistributed, however you may use the web service on your own site to supply a list of what is available.
The Community MX web service utilizes a standard .wsdl file that can be consumed by any technology that can consume a web service. The web service is located at http://www.communitymx.com/services/cmxfeed.wsdl. The web service exposes 4 methods:
*not implemented yet
Dreamweaver MX is the tool of choice for building ColdFusion MX pages because of the built-in features for CF MX, such as the Components panel which simplifies the process of building and consuming web services. The Components panel allows you to specify a URL for the .wsdl file, and the web service consumer code is created automatically by Dreamweaver MX. We'll show you how to add the getContent, searchContent, and getContentTypes services to your ColdFusion page.
The getContent method simply returns the latest content to your service without any kind of filtering, or filtering by contentType only. It is essentially a dump of the the latest content descriptions from the site. The next section will show how to consume the service using Dreamweaver MX.
<cfinvoke
webservice="http://www.communitymx.com/services/cmxfeed.wsdl"
method="getContent"
returnvariable="aObjectArray">
<cfinvokeargument name="type" value="enter_value_here"/>
</cfinvoke>
The <cfinvoke> tag invokes the web service from the webservice URL. The method is getContent, and it returns an array of objects. As you can see, there is an optional argument for "type". We will use the default option of 0 to show all types of content:
<cfinvoke
webservice="http://www.communitymx.com/services/cmxfeed.wsdl"
method="getContent"
returnvariable="aObjectArray">
<cfinvokeargument name="type" value="0"/>
</cfinvoke>
<cfloop from="1" to=#ArrayLen(aObjectArray)# index="i">
<table>
<tr>
<td>Title</td>
<td><cfoutput>#aObjectArray[i].Title#</cfoutput></td>
</tr>
<tr>
<td>Keywords</td>
<td><cfoutput>#aObjectArray[i].Keywords#</cfoutput></td>
</tr>
<tr>
<td>Author</td>
<td><cfoutput>#aObjectArray[i].Author#</cfoutput></td>
</tr>
<tr>
<td>Category</td>
<td><cfoutput>#aObjectArray[i].Category#</cfoutput></td>
</tr>
<tr>
<td>Type</td>
<td><cfoutput>#aObjectArray[i].type_description#</cfoutput></td>
</tr>
<tr>
<td>Description</td>
<td><cfoutput>#aObjectArray[i].description#</cfoutput></td>
</tr>
</table>
</cfloop>
The page code can be viewed here (you might have to View Source in your browser).
The searchContent method returns the latest content to your service using search criteria that you provide. It is a search of the latest content descriptions from the site, just as if you were searching the site itself from a search box on the site. The next section will show how to consume the service method using Dreamweaver MX.
<cfinvoke
webservice="http://www.communitymx.com/services/cmxfeed.wsdl"
method="searchContent"
returnvariable="aObjectArray">
<cfinvokeargument name="search" value="enter_value_here"/>
<cfinvokeargument name="anyWords" value="enter_value_here"/>
<cfinvokeargument name="exactPhrase" value="enter_value_here"/>
<cfinvokeargument name="contentType" value="enter_value_here"/>
<cfinvokeargument name="contentDate" value="enter_value_here"/>
</cfinvoke>
As you can see there are 5 optional arguments: search, anyWords, exactPhrase, contentType, and contentDate.
search: the search word or words. This can be individual words, comma separated
words, or phrases
anyWords: true to match
any of the search words, rather than the default of "all words"
exactPhrase: true to match an exact phrase
contentType: 0 for all, or match one of the CMX content types,
which
can
be found by using
the getContentTypes method of the service
contentDate: search based on a time period, as number of
days (defaults to 30)
<cfinvokeargument name="search" value=#form.search#
/>
<cfinvokeargument name="anyWords" value="false" />
<cfinvokeargument name="exactPhrase" value="false" />
<cfinvokeargument name="contentType" value="0" />
<cfinvokeargument name="contentDate" value="30" />
<form name="form1" method="post" action="example2.cfm">
<input name="search" type="text" id="search">
<input type="submit" name="Submit" value="Search">
</form>
<cfparam name="form.search" default="test">
<cfif form.search NEQ "" AND ArrayLen(aObjectArray) EQ 0>
<h2>No
matches found.</h2>
</cfif>
The page code can be viewed here (you might have to View Source in your browser).
To add a content list to the search, utilize the getContentTypes method of the service. These content types are generated dynamically because of the changing nature of the Community -- new content and content types are being added regularly. As of this writing, the getContentTypes method returns this result:
0, ALL
1, Article
2, Tutorial
3, FAQ
4, Review
5, Extension
6, Daily Tips
7, Weekly Tips
1000, Knowledge Base
The method returns an array of objects. Each object contains a type_id and a type_desc. These properties can be fed into a dropdown list. To add the dropdown list to Example 2, follow these steps:
<select name="contentType">
<cfloop index="j" from=1 to=#ArrayLen(theArray)#>
<cfoutput>
<option value="#theArray[j].type_id#"
<cfif form.contenttype
EQ theArray[j].type_id>selected="selected" </cfif>>#theArray[j].type_desc#</option>
</cfoutput>
</cfloop>
</select>
As you can see, the type_id and type_desc properties feed the list.
<cfparam name="form.search" default="">
<cfparam name="form.contenttype" default="0">
The page code can be viewed here (you might have to View Source in your browser).
Lastly, we'll show you how to fully utilize the searchContent method using all 5 arguments that the method will take. The example will be based on Example 3 and use that as a starting point. The previous example showed the use of the search and contentType arguments. This example will add the anyWords, exactPhrase, and contentDate arguments.
<form name="form1" method="post" action="">
<table width="445">
<tr>
<td><div align="right">Content type: </div></td>
<td>
<select name="contentType">
<cfloop index="j" from=1 to=#ArrayLen(theArray)#>
<cfoutput>
<option value="#theArray[j].type_id#" <cfif form.contenttype
EQ theArray[j].type_id>selected="selected" </cfif>>#theArray[j].type_desc#</option>
</cfoutput>
</cfloop>
</select></td>
</tr>
<tr>
<td><div align="right">Search type:</div></td>
<td>
<select name="searchtype" id="select2">
<option value="0" <cfif form.searchtype EQ 0>selected="selected" </cfif>>All
words</option>
<option value="any" <cfif form.searchtype EQ "any">selected="selected" </cfif>>Any
words</option>
<option value="exact" <cfif form.searchtype EQ "exact">selected="selected" </cfif>>Exact
Phrase</option>
</select></td>
</tr>
<tr>
<td><div align="right">Date range: </div></td>
<td>
<select name="daterange" id="select3">
<option value="7" <cfif form.daterange EQ 7>selected="selected" </cfif>>Past
week
<option value="30" <cfif form.daterange EQ 30>selected="selected" </cfif>>Past
month
<option value="90" <cfif form.daterange EQ 90>selected="selected" </cfif>>Past
90 days
</select></td>
</tr>
<tr>
<td><div align="right">Search for: </div></td>
<td><input name="search" type="text" id="search2" value="<cfoutput>#form.search#</cfoutput>">
<input type="submit" name="Submit" value="Search"></td>
</tr>
</table>
</form>
<cfparam name="form.searchtype" default="0">
<cfparam name="form.daterange" default="0">
<cfparam name="anyWords" default="false">
<cfparam name="exactPhrase" default="false">
<!---if the searchtype dropdown is
for any words--->
<cfif form.searchtype eq "any">
<cfset anyWords = "true">
</cfif>
<!---if the searchtype dropdown
is for exact phrase--->
<cfif form.searchtype eq "exact">
<cfset exactPhrase = "true">
</cfif>
<cfinvoke
webservice="http://www.communitymx.com/services/cmxfeed.wsdl"
method="searchContent"
returnvariable="aObjectArray">
<cfinvokeargument name="search" value=#form.search# />
<cfinvokeargument name="anyWords" value=#anyWords# />
<cfinvokeargument name="exactPhrase" value=#exactPhrase# />
<cfinvokeargument name="contentType" value=#form.contentType# />
<cfinvokeargument name="contentDate" value=#form.daterange# />
</cfinvoke>
Browse the page and it should now allow you to specify the type of search you want to perform as well as a date range.
The page code can be viewed here (you might have to View Source in your browser).
Web services can be built easily in Dreamweaver MX, and ColdFusion programming techniques, such as looping through arrays, can be easily utilized. The CMX web service can be used to freshen the content on your own pages by offering new content links every day.