| home / programming / coldfusion / 1 | [previous] [next] |
|
|
In the previous section, I mentioned that to call a web service, you must provide either the absolute URL to the web service's WSDL file or the name of the web service as registered in the ColdFusion Administrator. All of the examples I gave used the first method. The second method consists of registering the web service with the ColdFusion Administrator and assigning it a name. This allows you to refer to frequently accessed web services using an alias, as opposed to having to remember the (often verbose) URL to the WSDL file. It also allows you to avoid having to hardcode the URL to a web service's WSDL file in your application code. By registering the URL in the ColdFusion Administrator, you merely have to update a changed URL once in the ColdFusion Administrator, as opposed to everywhere you use it within your application code.
So, how do you go about registering web services in the ColdFusion Administrator? Well, registration happens automatically, at least partially. What I mean by this is that the first time you call a web service using any of the methods we've already discussed, the web service is automatically registered in the ColdFusion Administrator. All you have to do is go in and provide a name (alias) for the web service. To do this, follow these steps:
currencyExchange.
Remember, the point is to register the web service with an easy-to-remember
name that you can use in your application code to simplify the calling of
web services.
:password
in the authorization header to the target server. By specifying the username
and password here, you avoid having to provide the parameters when using the
cfinvoke tag to call a secured web service. For
more information, see the section on "Web Services Security" at
the end of the chapter.
|
|
Using the steps provided, it's also possible to register a new web service that hasn't yet been called from your ColdFusion server.
Once you have created an alias for your registered web service,
you can use the alias instead of the full URL to the WSDL file whenever you
need to consume the web service. Thus, to invoke the currency exchange web service
(assuming you registered its alias as currencyExchange),
you would use the following:
<cfinvokewebservice="currencyExchange"method="getRate"returnvariable="aRate"><cfinvokeargument name="country1" value="united states"/><cfinvokeargument name="country2" value="euro"/></cfinvoke><cfoutput>1 USD = #aRate# Euros</cfoutput>
| home / programming / coldfusion / 1 | [previous] [next] |
Created: March 27, 2003
Revised: Sept 1, 2003
URL: http://webreference.com/programming/coldfusion/1