15.2. Using Web Services for Data Source

The steps for specifying a Web service as a data source for an InfoPath form are almost as easy as, if not easier, than those used for specifying a table in a database for a data source. InfoPath performs a number of the steps for you.

The first thing you have to specify is whether you are receiving (querying) or submitting data. For now you will see quickly how to specify a Web service for viewing data.

After specifying what you want to do with the data (receive and/or submit), you will need to specify where the Web service you want to use is located. For the purpose of locating the Web service, you can utilize the UDDI directories, displayed in Figure 15-3, on the prior page. To help you locate the Web service, Microsoft supplies a dialog box, displayed in Figure 15-7.

Figure 15.7. Figure 15-7

For the purposes of this chapter, the Web services used will be located on the local machine at http://127.0.0.1, so the dialog box displayed in Figure 15-7 will not be used. You can also test using http://localhost.

Once you have specified the Web service, the wizard will walk you through the steps to specify which methods to use. After the wizard is completed, you will then need to bind the fields displayed to the various controls just as you do when using other types of data for data sources.

15.2.1.

15.2.1.1. Try It Out: Basing an InfoPath Form on a Web Service

To start off, you will be using an InfoPath form to display information from a Web service. While here you will be seeing how to specify a Web method as an InfoPath data source, in the following sections you will see the code on the Web service side that makes up the data connection. To start:

  1. Open InfoPath.

  2. Click Design a Form. The Design a Form task pane will be displayed on the right-hand side of the application.

  3. Click the task New from a Data Connection in the Design a Form task pane. The first page of the Data Connection Wizard will be displayed.

  4. Select Web Service from the first page, as shown in Figure 15-8.

    Figure 15.8. Figure 15-8
  5. Click Next to continue with the Data Connection Wizard. The next page asks you if you want to receive and submit data, submit data, or just receive data. For the purposes of this task, you will just receive data.

  6. Choose Receive data, as shown in Figure 15-9.

    Figure 15.9. Figure 15-9
  7. Click Next. The page displayed is where you will supply information about the Web service you want to use. In this case, you will be using your localhost service, or IP address, 127.0.0.1.

    You will next be supplying the Web service name, in this case Chapter15Webservice, and the main page of the Web service Service1.asmx. Finally, you add the ?, which tells Web pages you are sending a query, and the letters WSDL, which informs the Web service that you want the descriptions of the available methods and properties of the Web service. You can see the full string supplied for this example in Figure 15-10.

    Figure 15.10. Figure 15-10
  8. Click Next. The wizard queries the URL you specified to see if it can read the WSDL. If so, you see the list of methods provided by the sample application, as shown here in Figure 15-11.

    Figure 15.11. Figure 15-11

    If you have specified the URL incorrectly, then a message box will appear, and you will need to click Back in the wizard.

  9. Select GetSupplierInfoDS, and click Next. The next page displays all the parameters that will be used for querying the data. In this case, SupplierID will be used. To have InfoPath understand how to query the data correctly, you have to supply a sample for the query. In this case supply the value of 1, then InfoPath can do the rest of the work.

  10. Click Set Sample Value.... The Parameter Details dialog box opens.

  11. Type in 1, as shown in Figure 15-12.

  12. Click OK to accept the value, and then click Next in the Data Connection Wizard. The summary page, which is also the last page of the wizard, is displayed, as shown in Figure 15-13. You can also change the name used for the data connection you want on this page.

  13. Click Finish. The wizard is now complete and a query form template is displayed.

  14. Click the Data Source task pane, and then expand the two branches queryFields and dataFields, as shown in Figure 15-14.

    These should look familiar because they also are using a database for the data connection.

    Figure 15.12. Figure 15-12

    Figure 15.13. Figure 15-13

    Figure 15.14. Figure 15-14
  15. Drag the SupplierID field from the queryFields into the table under the button labeled Run Query.

  16. Drag and drop the Table node from dataFields data source branch under the table that has the label Click to add form content. You will then see the sections menu appear, letting you choose how you want to set the section up.

  17. Pick Controls in Layout Section from the displayed menu. The fields will now all be displayed as shown in Figure 15-15.

    That's all there is to it. Now, the last step is to preview the form just as would any other form.

  18. Click Preview form. The empty form is now displayed, ready for you to enter a supplier ID to query.

  19. Type 1 in the text box under the label Supplier ID.

  20. Click Run Query. The parameter is supplied to the Web service, and the result is returned to the form to be displayed, as shown in Figure 15-16.

    Figure 15.15. Figure 15-15

    Now comes the fun part. If you've read Chapter 13, "Working with .NET Managed Code," along with the Chapter 14, "Real-World Tasks and Coding Examples," you should be somewhat comfortable with Visual Studio .NET 2003. One of things not covered was using ASP.NET and developing for the Web. This next section provides an introduction to just that.

    Figure 15.16. Figure 15-16
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.12.230