Partager via


Accessing XML Web Services

Support for XML Web services in Visual FoxPro provided by the Microsoft SOAP Toolkit make it possible for you to access XML Web services from the Web. The extensions provided by the SOAP Toolkit 3.0 provide access to XML Web services using the Toolkit's SoapClient object. This high-level late-binding access architecture makes it possible for you to call an XML Web service method directly using only a few lines of simple object code.

The WSHandler foundation class, which is included with the _WS3Client.vcx class library in the ...\Ffc folder, is the XML Web service class used for all Visual FoxPro XML Web service calls.

Registering XML Web Services

Before using an XML Web service in your application, register it in Visual FoxPro. You can then select the XML Web service in the Visual FoxPro Toolbox and use operation or method calls from that XML Web service to return results. When calling the XML Web service, you can set the results to a property of a specified control, such as the TextBoxValue property.

Note   You do not have to register an XML Web service to access it; however, registering an XML Web service makes it possible for Visual FoxPro to provide IntelliSense for the XML Web service methods and their parameters.

To register an XML Web service

  1. On the Tools menu, click Task Pane.
  2. On the Task Pane Manager toolbar, click More Panes, and then click XML Web Services.
  3. In the XML Web Services pane, click Register an XML Web Service.
  4. In the Visual FoxPro XML Web Services Registration dialog box, type the Web Services Description Language (WSDL) URL for the XML Web service, and then click Register.

You also can open the Visual FoxPro XML Web Services Registration dialog box programmatically as shown in the following code:

DO (_wizard) WITH "project",,"Web","IntelliSense"

For more information about the settings you need to configure, see Visual FoxPro XML Web Services Registration Dialog Box.

Calling XML Web Services

After you register an XML Web service in Visual FoxPro, you can call and bind the XML Web service to a control or object on a form You can then process results from the XML Web service in your application. You can call and bind XML Web services using the XML Web Service Builder or in code. The builder provides extensive binding capabilities without your having to write code. For more information, see XML Web Service Builder.

The following steps illustrate how to call the XML Web service in your program using code.

To call an XML Web service using code

  1. On the Tools menu, click Toolbox.

  2. In the Toolbox, click My XML Web Services.

  3. Open an editing window to the location in your program or code where you want to call the XML Web service.

  4. Drag and drop the XML Web service in the editing window.

    The code for the XML Web service appears in the editing window.

You can also type the characters, ws, in the editing window. The Select dialog box appears so that you can select an XML Web service and any additional options and insert code for the XML Web service in the editing window. For more information, see Select Dialog Box.

You can use IntelliSense to see the available methods and parameters for the XML Web service. For example, IntelliSense displays a list of methods available for the XML Web service when you type the following line of code in the editing window:

? YourXMLWebService.

Note   Make sure to replace MyXMLWebService with the XML Web service object provided in the code.

You can select a method and continue typing as follows to specify parameters for the method:

? MyXMLWebService.WSMethod(

Note   Replace WSMethod with the XML Web service method you select.

IntelliSense displays the possible parameters and the return type for that method.

You can also port the code for the XML Web service to another computer that does not have the XML Web service registered. Visual FoxPro can detect that the XML Web service is not registered and prompts you to register it. If you do not want to register the XML Web service, you can remove the line that contains the WSDL reference, for example:

* __VFPWSDef__: lofoxtypes=http://mywebserver/foxws/foxtypes.wsdl

For more details about accessing XML Web services using high and low-level calls, see the SOAP Toolkit 3.0 documentation.

Binding XML Web Services to Controls

You can bind an XML Web service to a control or object on a Visual FoxPro form and assign the results of the XML Web service to properties of the control or object.

To bind an XML Web service to a control

  1. Create a new or open an existing form or class.

  2. On the Tools menu, click Toolbox.

  3. Under My XML Web Services in the Toolbox, drag and drop the Generic Handler control or the registered XML Web to a form or class.

    The XML Web Service Builder appears so that you can bind the XML Web service to controls or objects on the form. If the builder does not appear, right-click the XML Web service control and select Builder.

For more information, see XML Web Service Builder.

Note   It is recommended that you save a newly created form before dropping an XML Web service because the builder needs to access controls on the form using the container path.

See Also

XML Web Services in Visual FoxPro | Distributing XML Web Services