Redirect your application to different XML Web Services during installation

zhaozj2021-02-16  68

Redirect your application to different XML Web Services during installation

Steeve Hoagvisual Studio Teammicrosoft Corporation 2001 Abstract: This article describes how to create a web application in Visual Basic ?NET, redirect the application to different by using the URL Behavior property, the Installer class, and Web installer items. XML Web Services. table of Contents

Introduction URL Behavior Add Installer Class to Dynamic Add Setup Project Add Installer Class to Customize Add User Interface Dialog Generation and Installation Summary Introduction Introduction When developing an application with XML web services as a target, you should usually use a web server. The installed XML Web Services is the target. This is a guideline, but when deploying the product version of the application, sometimes you need to target other XML Web Services. For example, you may have a beta version of the XML Web Services on the development server as a target, but the completed application needs to use the installation version of the XML Web Services on another server as a target. You may also want to install the application to select the version of XML Web Services during the installation, such as version of the intranet or version of the version of the firewall can be accessed. This article describes how to create a web application that can redirect to different XML Web Services. The creation process includes:

Specify URL Behavior properties to find XML Web Services at runtime. Adding a mounting component that can perform a custom operation at the end of the installation. Use the installer item to create a installer that contains a custom user interface for the application. The first step is to create a web application that contains web references to XML Web Services. For more information on creating a web application, see Walkthrough: Creating An Xml Web Services Using Visual Basic Or Visual C # (English). Setting URL Behavior to Dynamic In order to find XML Web Services at runtime, the application will store the URL of the XML Web Services. The URL BEHAVIOR attribute for the web reference (for XML Web Services) determines the storage location of the URL. If the URL Behavior property is set to Static (default), the URL will be hard coded as part of the web reference. If the URL Behavior property is set to Dynamic, the specified URL entry will be added to the AppSettings section of the web.config file of the application. Set the URL Behavior property to Dynamic

In the Solution Explorer (Solution Explorer), expand the Web References node and select the reference to XML Web Services. In the Properties window, select the URL BEHAVIOR attribute and change it to Dynamic. In the Solution Explorer (Solution Explorer), select the web.config file and double-click to open the file. At the end of the file, you should find one

Segment, which contains the keywords specifying the XML Web Services name and the value of the specified URL. For example, for applications that are named MyWebApp on the local computer, the appearance is similar to: value = http://localhost/mywebservice/service1.asmx/>

The next step is to add an Installer class for modifying the .config file during installation. Adding an Installer class Installer class (also known as installation components) is a .NET framework class that is called as custom operation during installation. In this case, you need to add an Installer class to replace the Install method to add the code that modifies the .config file. For more information on the Installer class, see "Introduction to Installation Components" in the Visual Studio .NET document. Add INSTALLER Class

In the Project menu, select Add New Item. In the Add New Item dialog box, select Installer Class (Installer Class) and change the Name to WebServiceInstaller. After you click Open, this class will be added to your project and open the designer that contains the Installer class. Double-click the designer to open the Code Editor. Adding the following code for the Install method in the bottom of the Installer class module (above): Public overrides sub install (Byval StateAver as system.collections.idictionary) Getting parameters passed in CustomActionData. Dim installlog As New System.IO.StreamWriter ( "Installation.log") installlog.AutoFlush = True Try Dim ProvidedName As String = Me.Context.Parameters.Item ( "ServerName") Dim SvcName As String = Me.Context.Parameters. Item ("ServiceName") InstallLog.Writeline ("Start Edit Profile") if providesdname = "" or svcname = "" "" Unidentified Parameters ") end if 'uses the location of the configuration file using the reflection lookup configuration file. Dim Asm As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly Dim strConfigLoc As String strConfigLoc = Asm.Location Dim strTemp As String strTemp = strConfigLoc strTemp = strTemp.Remove (strTemp.LastIndexOf ( "/"), Len (strTemp ) - strTemp.lastIndexof ("/")) STRTEMP = strTemp.remove (strTemp.lastIndexof ("/"), len (strTemp) - strTemp.lastIndexof ("/")) Dim fileInfo as system.io.fileinfo = New INSTALLOG.WRITELINE ("File Information:" & Strtemp) INSTALLLOG.WRITELINE ("File Information:" "Missing Profile") End IF 'Loading Profiles To XML DOM.

DIM XMLDocument as new system.xml.xmldocument () Xmldocument.load (fileInfo.fullname) 'found the correct node and change it to a new value. DIM Node as system.xml.xmlnode Dim Foundit as boolean = false for Each Node in XmlDocument.Item ("configuration"). Item ("appsettings") 'Ignore all comments. If node.name = "add" ..getnamedItem ("key"). Value = "Appname.servername.service" THEN 'Note, "service1.asmx" should be replaced with the actual name of the' Web Service file . Node.Attributes.GetNamedItem ( "value") Value = "http: //". & ProvidedName & "/" & SvcName & "/Service1.asmx" FoundIt = True End If End If Next Node If Not FoundIt Then Throw New InstallException ("Profile does not contain a servername section") Endiff 'writes a new configuration file. XmlDocument.save (FileInfo.fullname) Finally InstallLog.writeline ("Editing of the Configuration File") InstallLog.close () End Try End Sub The above code first creates a installation log file for logging a custom operation schedule. System.Reflection namespace is used to find the installed assembly and look up the associated .config file. The XML document model is used to traverse the .config file until you find the appsetting section. After finding the keyword appname.servername.service, its associated value will change to include incoming parameters to re-direction to use the new XML Web Services. In the Solution Explorer (Solution Explorer), select the web.config file and double-click to open the file. Copy the keyword value of XML Web Services in the AppSettings segment. The keyword is appname.servername.service, where appname is the name of the application, ServerName is the server where XML Web Services is located, service is the name of XML Web Services. Open the Installer class module in the Code Editor and replace the appName.ServerName.Service using the value replicated in the previous step. The next step is to add a installer item to the application. Adding an installer project installer project is used to create an installer for your application. The installer project is based on Windows installer technology, which is included to run custom operations during installation and a number of functions such as custom installation user interfaces. For more information on installer projects, see Deploying Applications and Components in the Visual Studio .NET document. Add installer project

In the FILE (File) menu, point to Add Project, and then click New Project. In the Add New Project dialog, select the Setup and Deployment Projects in the Project Types pane. In the Templates pane, select Web Setup Project (Web Setup Project) and click OK. The project will be added to the solution and the File System Editor will be opened. In the Properties window, select the ProductName property and set its name to the same name as the application. In File System Editor, select the Web Application Folder (Web Application Folder). In the Action menu, point to Add (Add), and then click Project Output. In the Add Project Output Group dialog box, select the application project, then select Primary Output and Content Files, and click OK. The next step is to add a custom operation that will run at the end of the installation. Add the Installer class to custom operation custom operations to run the code at the end of the installation to perform operations that cannot be processed during the installation process. Customized code can be included in the .dll file, .exe file, script file, or assembly file. For more information on custom operations, see Custom ActionS Management in Deployment in the Visual Studio .NET document. Add an Installer class to custom operations

In the Solution Explorer (Solution Explorer), select SETUP PROJECT. In View menu, point to Editor, then click Custom Actions. The Custom Actions Editor will open. In the Custom Actions Editor, select the Install node. In the Action menu, select Add Custom Action. Double-click Web Application Folder, then select Primary Output, and click OK. In the Properties window, select the InstallerClass property and make sure it is set to True. Select the CustomActionData property and enter the following text: / servername = [edita1] / serviceData = [edita2] CustomActionData property provides two parameters that are passed to custom operations, and the parameters are separated by spaces. The next step is to add a user interface to enter information during the installation process. Adding a User Interface dialog box will display the user interface dialog box to collect information from the user. For more information on the User Interface dialog, see User Interface Management in Deployment (English) in the Visual Studio .NET document. Add Custom User Interface Dialog box in Solution Explorer, select Setup Project. In the View menu, point to Editor, then click User Interface. In the User Interface Editor, select the Start node. In the Action menu, select Add Dialog. In the Add Dialog dialog box, select TextBoxes (a) (Text Box [A]) dialog box, and then click OK. In the Action menu, select Move Up and repeat the operation until TextBoxes (a) (text box [a]) dialog is above the Installation Address dialog. In the Properties window, set the following properties:

Property Value Bannertext Entering Server Names and Service Name Edit1Label Server Name: Edit1Valuelocalhost

Note: This value specifies the default server. You can enter your own default server name here. Edit2Label Service Name: Edit2Value Edit3VisiblefalseEdit4Visiblefalse Note: Edit1Property property is set to "Edit5", and the Edit2Property property is set to "Edita2". These values ​​correspond to the values ​​entered in the CustomActionData attribute of the CUSTOM Actions Editor. If the user enters text during these editing controls during the installation, the CustomActionData property will automatically pass these values. Generating and install the final step is to generate an installer project to create an installer and then install the application to the target server. Generate installer projects

In the Build Projectname, select Build ProjectName, where ProjectName is the name of your installer project. Deploy the application to the development of the web server

In the Solution Explorer (Solution Explorer), select the installer project and then select Install in the Project menu. Deploy the application to the web server of other computers

In the Windows Explorer, browse to the project directory and find the generated installer. The default path is / Documents and Settings / Your Login Name / Setup Project Name / Item Configuration / Product Name. Msi. The default project is configured to debug. Copy the .msi files and all other files and subdirectories in the directory to the web server. On the web server, double-click the setup.exe file to run the installer. Summary We can see that it is not difficult to redirect applications to use different XML Web Services. Although this example uses XML Web Services to target web applications, you can easily change it to Windows applications: just use the app.config file instead of the web.config file, and use the installer project instead of Web Installer project. In addition, the process is exactly the same. This article describes several new technologies: Use the URL Behavior attribute to store information in the configuration file, using the Installer class during the installation, and store user information during the installation process using the CustomActionData property.

转载请注明原文地址:https://www.9cbs.com/read-15216.html

New Post(0)