Architecture of the Migrated PMS System Figure 12-12 shows the architecture of migrated application. Customers will continue to access the application through the TraderWorkStation project and the administrator through the SurveillanceMonitor project. These projects would not be upgraded to Visual Basic .NET. As the architecture shows, some COM components would be migrated to Visual Basic .NET and some of the COM components would be used as they are. The idea is to expose all the migrated and original COM components as Web services. That is, Web services would be created that act as wrappers around the original and the migrated COM components. Database access would be done through the COM and the .NET components . Figure 12-12. PMS Visual Basic .NET architecture Stock Services Component We will take a look at the VBStockService COM component. First of all we migrate the VBStockService to .NET using the upgrade wizard. The only issue is that the As Any parameter defined in the function GetProfileString will give a compilation error. Because As Any is not supported in Visual Basic .NET, we make this a string in the upgraded component. The strMessage parameter used in the function GetStockPrices was declared as a variant in Visual Basic 6.0 and hence gets upgraded to Object. This is changed to String in the upgraded component. Once the basic component has been migrated, the next step is to create a Web service, which acts as a wrapper around the upgraded component. To do so, add a reference to the upgraded .NET component as shown in Figure 12-13. Figure 12-13. Upgraded Stock Service component added as a reference in the Web service. The Web service has one method exposed as a Web service. The name is the same as that of the method in the COM component. The code follows : <WebMethod()> Public Function GetStockPrices() As String Dim objStockService As New _ VBCurrentStockPrices.CStockService() Dim strStockPrice As String Dim strMessage As String Dim arrayRecords() As String Dim strFields() As String Dim strRecord As String Dim strXMLString As String Dim iRecordCounter As Integer Dim iFieldCounter As Integer strXMLString = "<?xml version=""1.0"" ?>" strXMLString = strXMLString & "<Stocks>" objStockService.GetStockPrices(strStockPrice, _ strMessage) strStockPrice = Left(strStockPrice, _ Len(strStockPrice) - 1) arrayRecords = Split(strStockPrice, ",", -1, 1) For iRecordCounter = 0 To UBound(arrayRecords) strXMLString = strXMLString & "<StockDetails>" strRecord = arrayRecords(iRecordCounter) strFields = Split(strRecord, "^", -1, 1) strXMLString = strXMLString & _ "<StockId>" & strFields(0) & "</StockId>" strXMLString = strXMLString & _ "<PriceDate>" & strFields(1).ToString() & _ "</PriceDate>" strXMLString = strXMLString & _ "<Price>" & strFields(2).ToString() & _ "</Price>" strXMLString = strXMLString & _ "<LowPrice>" & strFields(3).ToString() & _ "</LowPrice>" strXMLString = strXMLString & _ "<HighPrice>" & strFields(4).ToString() & _ "</HighPrice>" strXMLString = strXMLString & _ "<OpeningPrice>" & strFields(5).ToString() & _ "</OpeningPrice>" strXMLString = strXMLString & _ "<ClosingPrice>" & strFields(6).ToString() & _ "</ClosingPrice>" strXMLString = strXMLString & _ "<LastTradedAQuantity>" & _ strFields(7).ToString() & _ "</LastTradedAQuantity>" strXMLString = strXMLString & "</StockDetails>" Next strXMLString = strXMLString & "</Stocks>" GetStockPrices = strXMLString End Function Thus, the StockService basically uses the migrated VBStockService component. Internally it calls the migrated COM component's GetStockPrices method. The values returned are then converted into an XML string and returned. You need to copy the StockService folder into the wwwroot subdirectory of the Inetpub folder in your IIS and create the StockService application. The URL for the Web service is http://localhost/StockService/StockService.asmx. Now, in the TraderWorkStation , we need to remove the reference to the VBStockServiceCOM and put in a reference to the newly created Web service. To do this, first of all a proxy class should be generated for the Web service. The following commands can be given at the command prompt to generate the proxy class: Wsdl /language=VB /out=StockService.vb /namespace=StockProxy http://localhost/StockService/StockService.asmx?wsdl This will generate a proxy class file called StockService.vb . Because this is .NET code, it has to be exposed as a COM component for the Visual Basic 6.0 application. The generated class file is modified with the following attributes. First of all generate a strong name key file with the following command: Sn k StockServiceKey.snk Once the key file is generated, it is used in the proxy class as follows. This will ensure that the assembly will be created with a strong name. The System.Reflection and System.Runtime.InteropServices are imported to expose the .NET component as a COM component: Imports System Imports System.ComponentModel Imports System.Diagnostics Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.Xml.Serialization Imports System.Reflection Imports System.Runtime.InteropServices ' 'This source code was auto-generated by wsdl, 'Version=1.0.3705.0. ' <Assembly: AssemblyKeyFile("StockServiceKey.snk")> Namespace StockProxy Use the following attribute before each method that must be exposed as a COM component: System.Runtime.InteropServices.ComVisible(True)> _ The complete proxy class file is stored in the Stock_WebService_Proxy_Class folder for this chapter. Once the proxy class is done, compile with the following command at the command prompt: Vbc /t:library/r:System.dll /r:System.Web.dll /r: System.Web.Services.dll /r:System.Xml.dll StockServiceProxy.vb This will generate the StockService.dll file, which has to be added to the global assembly cache with the following command: Gacutil /if StockService.dll Now register the .NET component as a COM component with the following command: Regasm StockService.dll /tlb This will generate the .tlb file. This file can be added as a reference to the TraderWorkStation project, and this application can now access the Web service as shown in Figure 12-14. Figure 12-14. TraderWorkStation referencing proxy classes. We have migrated the VBStockService to a .NET component and have created a Web service as a wrapper to the migrated COM component. In the TraderWorkStation application the calls to the CGI have to be replaced by calls to the Web service. The following code shows how the call was made to the CGI project for calling the VBStockService COM component: On Error GoTo errorHandler strURL = "http://pc-p33458/Scripts/" strURL = strURL & "Stock_System_CGI_trial.exe?" strURL = strURL & "method=GetStockPrices" sval = Inet1.OpenURL(strURL) nlen = Len(sval) Set objXmlDocument = New MSXML2.DOMDocument objXmlDocument.loadXML (sval) Set objRoot = objXmlDocument.documentElement This code is now replaced with the call to the Web service. The newproxy class is added as a reference to the TraderWorkStation project, the object of the proxy class is instantiated , and the method is invoked as shown in the following code: On Error GoTo errorHandler Set objStockProxy = New StockServiceProxy.cStockService sval = objStockProxy.GetStockPrices() Set objXmlDocument = New MSXML2.DOMDocument objXmlDocument.loadXML (sval) Set objRoot = objXmlDocument.documentElement In a similar way, all the COM component calls are to be replaced by calls to the Web service proxy classes. Login COM Component In the case of the VBLoginCOM component, we follow the same process as that for Stock services. We first upgrade the Login COM component using the upgrade wizard. The upgraded Login COM component is kept in the folder VBLoginCOM.NET for this chapter. A new Web service is created and then wrapped around the upgraded Login COM component. The Login Web service is kept in the LoginWebService folder of this chapter. You need to copy this folder to the wwwroot folder of the Inetpub directory of your IIS Web server. You would need to add a reference to the upgraded VBLoginCOM component and then compile the Web service. A proxy class has to be generated for the Login Web service and then it has to be exposed as a COM component for access to the TraderWorkStation application. You need to follow the steps listed for the Stock service to generate the proxy class and registering the class as a COM component. The proxy class for the Login Web service is kept in the Login_Webservice_Proxy_Class folder for this chapter. Admin COM Component For the VBAdminCOM component, we follow the same process as that of Stock services. In this case, we use the original COM component (instead of migrating the COM component). A Web service is wrapped around the original COM component. The Admin Web service is kept in the VBAdminWebService folder of this chapter. You need to copy this folder to the wwwroot folder of the Inetpub directory of your IIS Web server. You also need to add a reference to the original VBAdminCOM component and then compile the Web service. As in the case of the Stock services Web service, a proxy class has to be generated for the Admin Web service and then it has to be exposed as a COM component for access for the SurveillanceMonitor application. You need to follow the steps listed for the Stock service to generate the proxy class and register the class as a COM component. The proxy class for the Admin Web service is kept in the Admin_WebService_Proxy_Class folder for this chapter. Reports COM Component For the VBReportCOM component, we follow the same process we did for Admin services. In this case also, a Web service is wrapped around the original COM component. The Reports Web service is kept in the ReportsService folder of this chapter. You need to copy this folder to the wwwroot folder of the Inetpub directory of your IIS Web server. You also need to add a reference to the original VBReportsCOM component and then compile the Web service. A proxy class has to be generated for the newly created Reports Web service and then it has to be exposed as a COM component for access for the TraderWorkStation application. You need to follow the steps listed for the Admin service to generate the proxy class and register the class as a COM component. The proxy class for the Reports Web service is kept in the Reports_WebService_Proxy_Class folder for this chapter. BuySell COM Component For the VBBuySell component, we follow a different process. We use the SOAP ToolKit to expose this COM component as a Web service. The process of exposing the COM component as a Web service is explained in Chapter 13 in the ASP to ASP.NET migration case study. First of all a wsdl file is generated for the COM component and from this WSDL file, a proxy class is generated in much the same way as for the preceding components. |