Calling and Hosting FoxPro Web Services through .NETby Rick Strahl
Web Services with Visual FoxPro have never been easy. The most common Web Service tool for FoxPro is the SOAP Toolkit, which has been discontinued and which had a host of problems when dealing with complex types passed over Web Services. In this article I’ll show how you can leverage the powerful Web Service features of .NET and the new Windows Communication Foundation in your FoxPro application through COM Interop.
Discuss this article
By Rick Strahl
Rick Strahl is president of West Wind Technologies on Maui, Hawaii. The company specializes in Web and distributed application development and tools with focus on Windows Server Products, .NET, Visual Studio and Visual FoxPro. Rick is author of West Wind Web Connection, a powerful and widely used Web application framework for Visual FoxPro and West Wind HTML Help Builder. He's also a Microsoft Most Valuable Professional, and a frequent contributor to magazines and books. He is co-publisher and co-editor of CoDe magazine, and his book, "Internet Applications with Visual FoxPro 6.0", is published by Hentzenwerke Publishing. For more information please visit: http://www.west-wind.com/ or contact Rick at firstname.lastname@example.org.
Printer Friendly View
Debugging COM Interop AssembliesYou can easily debug .NET COM Interop assemblies from FoxPro by setting up the Visual FoxPro EXE (vfp9.exe) as an external debugging startup executable. To do this set the project Debug options and set Start External Program to the path of VFP9.EXE and the Working directory to the path of your application. Set your class library project as the startup project (in the Solution Explorer) and then simply Debug (F5) the application. The VFP IDE will start and you can Instantiate your COM object. Any breakpoints set in the .NET object will now break into the debugger.
Registering an Interop AssemblyUnlike standard COM objects you can’t use RegSvr32 to register .NET COM objects. .NET COM objects require special registration using a utility called RegAsm.exe. RegAsm.exe. .NET aware installers can automatically register .NET COM objects for you, or you can run RegAsm from your application. For more info on how to programmatically run RegAsm see: http://tinyurl.com/ycn4bl
COM Objects in ASP.NET 2.0In Visual Studio 2.0 with stock ASP.NET 2.0 projects COM Interop assemblies no longer automatically refresh when you make a change to the COM object. This means if you change your FoxPro COM object you have to remove the reference to the COM object and then add it back in. There is a workaround for this problem: You can create the Interop assembly in a separate Class project. When you do this Visual Studio will again check the COM typen library that it’s based on and re-import if the file has changed.
ComAttrib BugsThe COM _COMATTRIB functionality in FoxPro is useful in assigning proper typing and specific type names to FoxPro class members. It’s especially useful for property values. Unfortunely I’ve found that this type casting causes problems in .NET with certain types. Specifically DateTime and Object values types set with COMATTRIB fail to convert properly and show invalid values and won’t accept assigned values. The only workaround is to not assign an explicit type for these type descriptors and instead use the default Variant/Object type and manually cast in the .NET code.
WCF Configuration Files in FoxProConfiguration files with FoxPro are a little tricky because FoxPro uses different EXE files when running in development and with a compiled EXE at runtime. .config files map to the executing EXE so a configuration must be named with the name of the application. This means if you’re running in development the config file is vfp9.exe.config, while in a compiled application the config file is yourapp.exe.config. Make sure you remember to make any config file settings in both places or your development and runtime environments may not sync up.