Dreamweaver

Add a web service to a page

After selecting a web service, generating its proxy, and adding it to the Components panel, you insert it in a page.

The following example shows the Components panel with the web service proxy Helloworld added. The Helloworld proxy provides one method, sayHello, which prints “Hello World.”

Components panel with web service proxy

The following example instantiates the HelloWorld web service using ColdFusion.

  1. In the Document window, in Code view, drag the sayHello method into the page’s HTML.

    Dreamweaver adds the method and dummy parameters to the page.

  2. Edit the inserted code with appropriate service instance names, data types, and parameter values, as required by the web service. The web service provides descriptions of the data types and parameter values.

    In the following ColdFusion example, the web service is enclosed by the <cfinvoke> tags. When developing a web service in ColdFusion, use <cfinvoke> to instantiate the web service and invoke its methods.

    <html>
    <head>
    <title>Web Service</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <cfinvoke 
    webservice="http://www.mysite.com:8500:8500/helloworld/HelloWorld.cfc?wsdl"
    method="sayHello"
    returnvariable="aString">
    </cfinvoke>
    </body>
    </html>
  3. To bind a return value to a visual element, switch to Design view and place a visual element on the page that can accept data binding. Then switch back to Code view and enter the appropriate code to bind the returned value to the visual element. When creating web services, refer to the technology provider’s documentation for the proper syntax with which to both instantiate the service and display the returned values to the page.

    In this example, the value returned for the variable aString is output using the ColdFusion <cfoutput> tag. This displays the sentence “The web service says: Hello world!” to the page.

    <html>
    <head>
    <title>Web Service</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <cfinvoke 
    webservice="http://www.mysite.com:8500/helloworld/HelloWorld.cfc?wsdl"
    method="sayHello"
    returnvariable="aString">
    </cfinvoke>
    The web service says: <cfoutput>#aString#</cfoutput>
    </body>
    </html>
  4. When you deploy web pages to a production server, Dreamweaver automatically copies the pages, the proxy, and any necessary libraries to the web server.
    Note: If you develop the application with a proxy that is installed on a separate computer from the one where you developed the pages, or if you use a site management tool that does not copy all of the related files to the server, you must ensure that you deploy both the proxy and any dependent library files. Otherwise, your pages cannot communicate with the web service application.