Building the Order Information 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.

After the data source is set up and the Query view completed, the only remaining task in building the Web Service developer sample form is completing the Data Entry view. When you set up the data source, Microsoft Office InfoPath generated a (blank) default Data Entry view that can display the orders information as soon as a few controls are bound to the data source.

Note  Before you start adding controls, you'll want to rename the Data Entry view and apply some basic formatting. To change the view name, double-click it in the Views task pane in design mode, and then type Order Information on the General tab of the View Properties dialog box. To add a title to the Order Information view, switch to Query view, select the entire title table (click in the table, and then click the square on the table's upper left corner), and copy it into the Order Information view. Change the title text as you like; you may also want to set the background and text color for each row in the table.

Add a repeating section for the order data

  1. In the Order Information view, click below the title, and then click Repeating Section in the Controls task pane. In the Repeating Section Binding dialog box, select the repeating group Order. Then select the Repeating Section control on the form and drag the bottom handle to enlarge the section enough to hold a table with three rows and two columns. (The table will hold the labels and controls that show an order's data fields.)

  2. Right-click the Repeating Section control and open the Repeating Section Properties dialog box. On the Data tab, clear the Allow users to insert and delete the sections check box.

  3. Click inside the Repeating Section control on the form. On the Table menu, point to Insert, and then click Layout Table. In the Insert Table dialog box, enter 2 columns and 3 rows. The following is one way to organize the data fields; for each field, click in the cell, and then click a control to enter it in the cell and select the field that is bound to the control.

    Column 1, row 1: text box, bind to OrderID.

    Column 1, row 2: text box, bind to OrderDate.

    Column 1, row 3: text box, bind to AverageDiscount.

    Column 2, row 1: text box, bind to CustomerName.

    Column 2, row 2: date picker, bind to ShippedDate.

    Column 2, row 3: text box, bind to Total.

    Note  You could use a repeating table instead of a repeating section; in this case, each field would be in its own column. You could also work from the Data Source task pane by expanding the dataFields group and dragging the fields into the table. The typical control is inserted for each field.

  4. For every text box, right-click or double-click it to open the Text Box Properties dialog box, click the Display tab, and select the Read-only check box. For the AverageDiscount and Total fields, you may also want to use the Format button on the Data tab to display the values as currency. Change the other text box formats as you like.

    Note  The date picker control cannot be set to read-only. That is why a text box was chosen for the OrderDate field.

Test the Order Information view

  1. From the Query view, preview the form. Then select an employee in the drop-down list and run a query as before. You should see the Order Information view populated with the orders data returned from the Web service for that employee.

  2. Click the date picker icon for the Shipped Date field in one of the orders and select a new date, or type a new date in the field.

  3. To submit the changed data, click Submit on the File menu. If you correctly configured the Web Service developer sample form to both receive and submit data, you should see a message that states, "The form was submitted successfully."

    Note  If the Submit item on the File menu is disabled, the form was not configured to submit data. In that case, follow the steps in the next section ("Submit a changed Shipped Date to the database").

  4. To confirm that the changed date was saved to the Web server's database, do one of the following:

    • Open the sample Web service database with Microsoft Access. The default database file path is <drive>:\Program Files\Microsoft Office 2003 Developer Resources\Microsoft Office InfoPath 2003 SDK\Samples\WebSvc\server\infnwind.mdb. Double-click the Orders table and check the date you changed.
    • In InfoPath, return to the Query view and run another query on the same employee. This returns fresh data from the Web service.

    If the Shipped Date was not changed, a Web service method that does not perform updates could have been selected. For example, if you selected either the getEmployees or getOrders method for submitting data, the form would successfully submit the data, as the message states, but essentially do nothing. The Web service never received the changed date because the data was not sent to an operation (method) that could "listen".

    If you receive a SOAP error, security permissions might not be set correctly for the Microsoft Internet Information Server (IIS) virtual directory or for the directory where the Web service database is located.

Submit a changed Shipped Date to the database

FileSubmitting FormsTools

  1. In the Order Information view, click in the empty area above the repeating section where you would like to add a button. In the Controls task pane, click Button to add a button to the form, and then open the Button Properties dialog box.
  2. In the Action list, click Submit to open the Submitting Forms dialog box.
  3. Click Enable submit, and then click Submit to a Web service in the Submit list. Click Select a Web Service, and then enter the sample Web service URL as before (http://localhost/Infopathsdk/infopathwebservicesample/InfoPathWebServiceSample.asmx?WSDL).
  4. When you select an operation for submitting your XML data, you'll need one that can accept the correct input. As you saw in the Web browser view of the WSDL URL, the correct operation is updateOrders.
  5. It's a good idea to check the XML element that will be sent to make sure it contains all of the data that the updateOrders operation needs and the data is the correct type. Remember, the operation input parameter must include the EmployeeID as well as an OrderList with all of the order data. Orders is an XML element that is a complex type—that is, it contains child elements, and the child elements contain all of the required data, so orders is the correct parameter type.
  6. Finish the Submit to Web Services Wizard, and then change the button caption and submit options if you want.

Save the form and extract the form files to see the files InfoPath added for the Submit action. The structure of the Submit action is stored in the file Submit.xml:

<dfs:myFields ... >
   <dfs:dataFields>
      <s0:updateOrders>
         <s0:orderList>
            <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:orderList>
      </s0:updateOrders>
   </dfs:dataFields>
</dfs:myFields>

Test the Order Information view again, as described previously. A changed and submitted shipped date should now remain changed.