Tuesday, February 1, 2011

How to Host MultiSpeak Web Services on Your Windows PC?

You can load the MultiSpeak web service definitions on a local PC for convenience. In order to do so you must have Microsoft's Internet Information Server (IIS) loaded on the PC.

How to install IIS and load the MultiSpeak web services on Windows XP Professional:


  1. Insert the Windows XP Professional CD-ROM into your CD-ROM drive.
  2. From the Start Button, go to Settings, and then Control Panel.
  3. In the Control Panel window, select Add/Remove Programs.
  4. In the Add/Remove window, select Add/Remove Windows Components.
  5. In the Wizard window, check Internet Information Services, leaving all of the default installation settings intact. Click NEXT. Wait for Windows to finish loading IIS, then click FINISH.
  6. An Inetpub folder will be created on your hard drive.
  7. Open the Inetpub folder and find the folder named wwwroot.
  8. Unzip the file named MultiSpeakBusArchitecture Vxxx MMDDYY.zip into the wwwroot folder (where Vxxx is the version name, e.g. V30qb for Version 3.0, bus build q, and MMDDYY is the date of the release).
  9. Next we would like to make sure that the web server is running. Open the Control Panel, then Administrative Tools, and double-click on the "Internet Information Services" icon. While in the Internet Information Services window, click the plus sign next to the name of your computer to expand the tree view, then click the plus sign on the "Web Sites" entry to expand that entry, and finally expand the "Default Web Site" entry by clicking its plus sign. Right click on "Default Web Site" and make sure that the word "Start" is greyed out; if not, click on "Start" to start the localhost web server.
  10. Next we want to create a virtual directory for the MultiSpeak web services. Right click on the "Default Web Site" entry, choose "New" and then "Virtual Directory" from the menu. A Virtual Directory Creation Wizard window will open. Follow the instructions to create a new virtual directory. Begin by choosing an alias name for the directory. For this example I will use the alias to be "MultiSpeakWebServices", but you could use any folder name you like. Click NEXT. The Virtual Direction Creation wizard will open. Next browse to the directory that was created when you unzipped the web services in the C:/Inetpub/wwwroot folder in step 8. It should have the same name as the zip file you unzipped in step 8. Click the NEXT button to accept the directory. Next the wizard will ask you to choose "Access Permissions". Accept the default access permissions by clicking the "Next" button, and then the "Finish" button to complete the wizard. The Internet Information Services window should now show a new entry under the "Default Web Sites" tree entry that is named "MultiSpeakWebServices" (or whatever name you chose when you created the new virtual directory in this step).
  11. In the Internet Information Services Manager window, right click on the new virtual directory that you just created, choose properties, and the ASP.NET tab in the Properties window. Make sure that the ASP.NET version is 2.0 or higher. If the ASP.NET tab does not exist, or if ASP.NET version 2.0 or higher is not an option from the pull down menu in the ASP.NET version box, then you will have to download the .NET Framework Version 2.0 or higher from the Microsoft web site. You can get the .NET Framework Version 2.0 download from: http://www.microsoft.com/downloads/details.aspx?FamilyID=0856EACB-4362-4B0D-8EDD-AAB15C5E04F5&displaylang=en . This will download a file named dotnetfx.exe. Follow the setup wizard to install dotnetfx.exe and repeat this step to ensure that the virtual directory defaults to ASP.NET version 2.0 or higher.
  12. Open your browser and type in http://localhost/MultiSpeakWebServices/IndexPage.aspx . If you chose a different name than "MultiSpeakWebServices" for your new virtual directory in step 11, substitute that name in the URL shown above (for instance if you used "MyNewVirtualDirectory" instead of MultiSpeakWebServices" the URL would be http://localhost/MyNewVirtualDirectory/IndexPage.aspx .
  13. The opening index page for the Web services should come up.


 

Sorting the methods alphabetically

If the web service methods are not displayed alphabetically, you can force ASP.NET to sort the methods by modifying the DefaultWsdlHelpGenerator.aspx page which is used to create that test page (%windir%\Microsoft.NET\Framework\v1.1.4322\CONFIG\DefaultWsdlHelpGenerator.aspx).  ASP.NET gathers up the description information for the requested web service/asmx and passes that data to the help generator page.  You can modify this page however you see fit (or you can tell ASP.NET to look in a different location for the generation page by modifying the machine.config's system.web/webServices/wsdlHelpGenerator node).

If you look in this file, you'll see around line 1285:

        Hashtable methodsTable = new Hashtable();
        operationExists = false;
        foreach (ServiceDescription description in serviceDescriptions) {
                foreach (PortType portType in description.PortTypes) {
                        foreach (Operation operation in portType.Operations) {
                                string messageName = operation.Messages.Input.Name;
                                if (messageName == null || messageName.Length == 0) messageName = operation.Name;
                                if (messageName == operationName)  operationExists = true;
                                if (messageName == null) messageName = String.Empty;
                                methodsTable[messageName] = operation;
                        }
                }
        }
        MethodList.DataSource = methodsTable;

The code is creating a hashtable of all of the methods available in the Web service and is then binding the repeater you see on the test page that lists all of the methods to this hashtable.  This sheds light one why the methods appear to be in no particular order on the test page: the code is enumerating a Hashtable rather than an ordered list, so the ordering is at the mercy of the hash values generated for messageName and thus the buckets into which the operations are placed.

To get the methods listed in alphabetical order, all we need to do is make a one line change, from:
        Hashtable methodsTable = new Hashtable();
to
        SortedList methodsTable = new SortedList();

Instead of being placed into a Hashtable, the operations will all be placed into the SortedList, indexed by messageName.  When MethodList is bound to methodsTable (which we would probably also want to rename just for clarity's sake), methodsTable will be enumerated in alphabetical order (thanks to SortedListEnumerator), and thus the methods listed on the test page will be in alphabetical order.

0 comments:

Post a Comment