McAlister Merchant
Microsoft Corporation
Created: March 2001
Revised: March 2001
Applies To: Microsoft Visual FoxPro
Web Services can be available anywhere. You can create them yourself, or you can access them over the Web from wherever they happen to be published. You can use Visual FoxPro to create Web Services, and if you register them in IntelliSense, Visual FoxPro makes it possible for you to access them almost automatically. You also can use Visual FoxPro to access Web Services created in other languages.
Establishing a Virtual Directory
Creating and Publishing a Web Service
Creating Web Services using Microsoft Visual FoxPro 7.0 is a complex process that involves using Microsoft Internet Information Services (IIS), Visual FoxPro COM servers, and Simple Object Access Protocols (SOAP). You use IIS to create a virtual directory that references the location on your hard disk where you place your services. IIS can be installed as part of the Microsoft Windows NT 4.0 Option Pack, with Mi 919k1010j crosoft Windows 2000 Professional, or automatically with Windows 2000 Server.
Then, you can use the Project manager to create or to compile COM objects. When the COM objects are created, you can use the Visual FoxPro Web Services wizard to publish them in your virtual directory.
You can use the IntelliSense manager to register Web Services with Visual FoxPro, so the placement of the Web Service and necessary calling routines in code is expedited.
This paper walks you through the processes involved in making Web Services of your existing COM servers and preparing Web Services for use. You create, from a COM server, a very simple Web Service that is accessible through HTTP by anyone. This Web Service provides a simple report of the current directory and how many .jpg files are there.
Web Services extend the accessibility to your own COM servers, as well as making Web Services from other developers accessible to you through your browser.
Web Services provide functionality and access to data between platforms and across diverse connections. You create and use Web Services to provide or to gain functionality from wherever it happens to reside. The most important aspect of Web Services is that, because of the way they use the HTTP protocol and the SOAP proxy, functionality is available through firewalls. Because HTTP and SOAP are platform agnostic, Web Services are also platform agnostic. In some cases, this can provide functionality that was unavailable under COM alone.
To publish a Web Service, you must create a virtual directory in IIS, and then create or copy a COM server from which you generate a Web Service to your virtual directory.
You must create or identify a directory into which you will place your Web Services. Although you can use an existing directory, you might want to create a separate place on your hard disk to store these files to make it easier to manage your Web Service files.
To create the virtual directory
Create a folder named Web Services in the main Visual FoxPro directory (..\Program Files\Microsoft Visual FoxPro 7).
In the Administrative Tools folder of the Microsoft Windows control panel, double click the Internet Services Manager shortcut.
The Internet Information Services window opens, displaying a tree in the left pane that shows your hard disk. Expand this node to see available sub folders.
Select the Default Web Site node in the Tree pane
From the right-click menu, select New, and click Virtual Directory. This opens the Virtual Directory Creation wizard.
Follow the steps in the wizard, and specify the Web Services folder that you created in Step 1 as your virtual directory.
You have created a virtual directory that references the Web Services folder in which you will store all the Web Services files you create.
The Project manager is the most fundamental application-building tool in Visual FoxPro. Within a Visual FoxPro project, you can assemble documents of all types, data, classes, code, and other file types. A project provides access to all the components you might want to include in a server and contains them for compilation. In this example, you use the project to compile your Web Service.
To create a project
In the File menu, select New.
In the New dialog box, select Project, and click New file.
In the Create dialog box, select the Web Services folder you created earlier, and name your project myWServ1.
Click Save.
Now, you have created your project in the Web Services folder. This makes it possible for you to save and compile the project to the correct folder automatically when you have finished adding components to it.
Because, a Web Service is a .dll or .exe file, you must use a COM server as the basis for your Web Service. A COM server in Visual FoxPro is a file with .dll or .exe extension containing a class built as OLEPUBLIC from a project. Objects specified as OLEPUBLIC are accessible by Automation clients. From the .dll file, a new .wsdl file will be generated when you publish the Web Service. This .wsdl file has the necessary XML code that describes the classes in the .dll and references which .dll file is the driving force behind that particular Web Service.
For this COM server example, you will create a custom class that reports some very simple information. In this process, you will write a program that creates the class with two methods and compile the project containing it into both a COM server and then a published Web Service.
To create a simple class
In the File menu, select New.
In the New dialog box, select Project, and click New file. This opens the Project Manager.
In the All tab of the Project Manager, expand Code, select Programs, and then click New.
Copy the following code into the code edit window.
*-- returns curdir() and number of JPEG files
DEFINE CLASS showem AS session OLEPUBLIC
Name = "showem"
PROCEDURE justshow
howmany=ADIR(afilArry,"*.jpg")
IF howmany <1
fileNm="no"
ELSE
fileNm=ALLTRIM(STR(howmany))
ENDIF
X = "about " + CURDIR() + " ... "
Y = "There are " + fileNm + " JPEG files here."
RETURN x + y
ENDPROC
ENDDEFINE
This program defines one class, showem, which has one method, justshow.
Close the edit window, and in the Save As dialog box, name the program myWServ1, and click Save.
Make
sure myWServ1 is set to
To compile the COM server
In the Project Manager, click the Build button.
Select Single-threaded COM server.
Click OK, and accept the name myWServ1.
Visual FoxPro will compile the myWServ1 file into a COM server, after which you can turn this COM server into a Web Service.
To add the components necessary to turn your COM server into a Web Service, you must compile the COM server as a Web Service. After you specify the settings, Visual FoxPro creates the XML and SOAP files necessary to turn your server into a Web Service, registers your new Web Service, and publishes it in your virtual directory.
To compile and publish a Web Service
After you have completed the previous procedures and compiled the COM server myWServ1.dll, right-click the Project Manager, and choose Builder from the shortcut menu.
In the Wizard Selection dialog box, choose Web Services Publisher, and then click OK.
In the Visual FoxPro Web Services Publisher dialog box, use the Ellipsis button (...) to locate myWServ1, and then select the class you want to register from that server. In the COM server you created, myWServ1, you have only one class, showem.
Note It is a good idea to click the Advanced button to make sure the Web Services Publisher dialog box is referencing the correct files, especially if you have created similarly-named servers or services in different folders. If the correct file is not displayed in the drop-down list, use the Ellipsis button (...) to locate the correct file. The IntelliSense scripts field displays the name under which you (and the SOAP toolkit) will find this Web Service. After verifying the information in the Advanced Web Services Publisher dialog box, click OK.
Click the Generate button.
After Visual FoxPro generates the Web Service files, the Web Services Publishing Results dialog box appears, displaying a list containing the COM server, .wsdl file, ISAPI or ASP listener, and IntelliSense path names and compilation results.
At this point, you have created and published your Web Service. Anyone who has access to the virtual directory you established earlier can use HTTP to access the Web Service you just created.
To use this Web Service, someone must write code that invokes the SOAP client, a listener, and the browser and must employ several layers of protocol and process. In Visual FoxPro, this is simplified by registering Web Services in the IntelliSense manager.
You can register Web Services (both those created by you and those created by others) in the IntelliSense manager. When you do this, IntelliSense provides the supporting code whenever you access a registered Web Service.
To Register a Web Service
In the Tools menu, select IntelliSense Manager.
In the Types tab of IntelliSense Manager, click the Web Services button to register your new Web Service (your new class also will appear in the Types list).
Now, IntelliSense will provide your Web Service as an optional selection whenever you add a strongly typed variable to your Visual FoxPro code.
You use a Web Service the same way you would any COM server to expose functionality of one application to another application or program. For example, you can create a Visual FoxPro program that calls the sample Web Service, myWServ1. In a Visual FoxPro program, declare a strongly typed variable as in the following line of code, in which you reference your Web Service, myServ1, by choosing it from the IntelliSense drop-down list:
LOCAL x AS myWServ1
Visual FoxPro IntelliSense uses the registered information on this Web Service to complete the following lines of code:
x = CREATEOBJECT("MSSOAP.SoapClient")
x.MSSoapInit("https://TheVirtualDisk/web services/ myWServ1.WSDL", , " myWServ1SoapPort")
Then, you call the method of that Web Service just as you do any COM object or class method as in the following code:
? x.justshow()
You can add similar code to access your own or other Web Services to Visual FoxPro programs and applications.
For more information on Web Services, see "Web Services Overview" in the Visual FoxPro Help. For more information on COM servers, see "Creating Automation Servers" in the Visual FoxPro Help.
Text for description meta tag: Visual FoxPro makes it possible for the creation of Web Services from COM servers.
Keywords: Visual FoxPro Web Services, creating; Visual FoxPro, creating Web Services; Visual FoxPro, Web Services
|