Building the Query View in the Web Service Developer Sample Form [InfoPath 2003 SDK Documentation]

Applies to:

Microsoft Office InfoPath 2003

Microsoft Office InfoPath 2003 Service Pack 1

For information on a new capability in Service Pack 1 that allows you to connect forms to Web services that receive data from and submit data to ADO.NET datasets, see About ADO.NET dataset integration in the InfoPath Developer's Reference.

Also in Service Pack 1, InfoPath creates a single default view, instead of two separate views, for the query and submit capabilities. The new default view is designed to guide solution developers by providing specific instructions in particular parts of the form.

After learning about the Web service, the next step is building the Query view for the Web Service developer sample form. This is a two-part procedure: The objective in Part 1 is to set up the data source for the entire form; this is accomplished in the Data Source Setup Wizard. Part 2 involves building the Query view with a secondary data source for the employee list.

Part 1: Set up the form's data source

  1. Start Microsoft Office InfoPath in design mode, and then click New from Data Source in the Design a Form task pane.

  2. In the Data Source Setup Wizard, click Web service, and then click Next.

  3. On the next page of the wizard, click Receive data, and then click Next.

    Note  You could click Receive and submit data here, and choose the correct Web service method for submitting data at the beginning of the form design process. This exercise demonstrates that you can create a form to receive data only, and then enable submitting data later with the Submitting Forms dialog box, which is accessed from the Tools menu.

  4. On the next page of the wizard, enter the URL of the sample Web service from which the form will receive data: http://localhost/infopathsdk/infopathwebservicesample/infopathwebservicesample.asmx.

    Note  The Search UDDI button opens the Search Web Service dialog box. UDDI is the Universal Description, Discovery, and Integration organization, which defines a standard for publishing and registering Web services in a global public or private directory. The sample Web service installed with the Microsoft Office InfoPath 2003 Software Development Kit is a local service only and is not registered in a UDDI service.

    It is not necessary to add the ?WSDL extension to the URL here, although you may. InfoPath will add ?WSDL to the URL if the first URL used does not return valid WSDL.

  5. The next page of the wizard shows the operations (methods) available; click an operation to see the description. Select the getOrders operation.

    Note  You are defining the data source for the entire form here, which will include both the Query view and the Order Information view. For this, you need all of the data that the getOrders operation provides. A secondary data source can be added later, to provide the employee names for the drop-down list box in the Query view.

  6. The summary page of the Data Source Setup Wizard shows a summary of the data sources you defined. Click Design query view first, and then click Finish. InfoPath generates a generic form, with a Query view and a Data Entry view. The Query view contains a table with a title and text, and a Run Query button that is used to query the data source and then switch to the Data view.

Save the form and extract the form files (click Extract Form Files on the File menu) to examine the current parts of the Web Service developer sample form. InfoPath stores the data included in the default form in the file template.xml:

<dfs:myFields ... >
   <dfs:queryFields>
      <s0:getOrders>
         <s0:employeeID></s0:employeeID>
      </s0:getOrders>
   </dfs:queryFields>
   <dfs:dataFields>
      <s0:getOrdersResponse>
         <s0:getOrdersResult></s0:getOrdersResult>
         <s0:orders>
            <s0:EmployeeID></s0:EmployeeID>
            <s0:OrderList>
               <s0:Order>
                  <s0:OrderID></s0:OrderID>
                  <s0:CustomerName></s0:CustomerName>
                  <s0:OrderDate></s0:OrderDate>
                  <s0:ShippedDate></s0:ShippedDate>
                  <s0:Total></s0:Total>
                  <s0:AverageDiscount></s0:AverageDiscount>
               </s0:Order>
            </s0:OrderList>
         </s0:orders>
      </s0:getOrdersResponse>
   </dfs:dataFields>
</dfs:myFields>

Part 2: Use a secondary data source for the Query view

  1. In the Query view, click above the Run Query button to set an insertion point, and then click Drop-Down List Box in the Controls task pane. In the Drop-Down List Box Binding dialog box, select employeeID in the queryFields group. Note that this is not the data source that the control will use, but you must select an item to place the control.

  2. Change the Employee ID label on the form to Employee Name. Select the list box control and drag the right handle to expand it. Right-click the list box control, and then click Drop-Down List Box Properties on the shortcut menu.

  3. In the Drop-Down List Box Properties dialog box, click Look up in a database, Web service, or file. The Secondary Data Source button and related fields appear. The list box needs to retrieve a list of all employee ID values from the Web service and display the employee names. The getOrders method is designed to return order data, not employee names, so another data source is needed.

  4. Click Secondary Data Source, click Add, and then click Web service in the Data Source Setup Wizard. Enter the Web service URL again, and this time select the getEmployees operation. This operation needs no parameters. On the wizard's summary page, enter a unique name for this data source, such as getEmployees4List, to help remember that it is a secondary source for the list box.

    Note  Make sure the Connect to this secondary data source when the form is opened check box is selected. If it is not selected, the list box will require additional script to query the secondary data source.

  5. Now you must create XPath expressions to extract the list of employee entries, along with their ID and display name values. Next to the Entries box in the Drop-Down List Box Properties dialog box, click the XPath button. In the Select a Field or Group dialog box, expand the list and select the Employee group. (The Entries field requires a repeating group; when you rest the mouse pointer on each item in the list of fields and groups, the ScreenTip shows that Employee is the only repeating group.)

  6. Now fill in the Value and Display name fields the same way, using the XPath buttons. Remember, the integer values are EmployeeID, and the names you want to see in the list box are the Fullname fields. Click OK, and you're nearly done with the Query view.

  7. This a good time to save your work. When you save an InfoPath form, you are offered the choice to save the form or publish it for other users. Click Save, and then in the Save As dialog box click Change Name if you want to name the form something other than Template1. All of the form files that InfoPath has generated are saved in a compressed form template file with an .xsn extension.

InfoPath stores the data of the secondary data source in the form file GetEmployees4List.xml:

<dfs:myFields ... >
   <dfs:queryFields>
      <s0:getEmployees></s0:getEmployees>
   </dfs:queryFields>
   <dfs:dataFields>
      <s0:getEmployeesResponse>
         <s0:getEmployeesResult></s0:getEmployeesResult>
         <s0:employees>
            <s0:Employee>
               <s0:EmployeeID></s0:EmployeeID>
               <s0:Firstname></s0:Firstname>
               <s0:Lastname></s0:Lastname>
               <s0:Fullname></s0:Fullname>
            </s0:Employee>
         </s0:employees>
      </s0:getEmployeesResponse>
   </dfs:dataFields>
</dfs:myFields>

Note  The form files GetEmployees4List.xsd and GetEmployees4List1.xsd are the XML schemas that are used to validate a Web service request and response. InfoPath uses these files during processing of the secondary data source query.

Now you can test the form's Query view. Click Preview Form on the Standard toolbar. You should see the employee names in the drop-down list box. Select a name, and then click Run Query. A blank view opens: this is because you have not yet added anything to the Data Entry view that InfoPath created in Part 1.