Common Simple Server task


PurposeThis sample demonstrates how to create a custom simple Web server task using the task framework included with the Web Application Developer Framework (ADF). This sample provides the code and steps necessary to enhance the Visual Studio design-time experience and plug the custom task into ArcGIS Server Manager (Manager).

How to use

If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

At design time
  1. Verify that the Web ADF for the .NET Framework is installed and functioning properly. For information on installing and configuring the Web ADF, consult the installation guide.
  2. In Windows Explorer, navigate to <ArcGIS install location>\DeveloperKit10.0\Samples\ServerNET. This folder contains a folder called Common_SimpleServerTask containing CSharp and VBNet folders.
  3. Open the folder of the language you are going to use (that is, CSharp or VBNet) and copy the Common_SimpleServerTask_<language> folder to c:\inetpub\wwwroot. The <language> variable can be CSharp or VBNet.
  4. Open the IIS Manager from Control Panel, Administrative Tools, Internet Information Services (IIS) Manager, or Internet Information Services.
  5. In the console tree view on the left, navigate to Local Computer, Web Sites, Default Web Site. Open the Common_SimpleServerTask_<language> folder, right-click the SimpleServerTaskWebApp_<language> folder, and click Properties. The Properties dialog box appears.
  6. Click the Directory tab, click the Create button in the Application Settings section, then click OK to close the Properties dialog box.
  7. Start Visual Studio 2010 and open the Common_SimpleServerTask_<language><vs_version> solution (for example, Common_SimpleServerTask_CSharp2010.sln) located in c:\inetpub\wwwroot\Common_SimpleServerTask_<language>.
  8. In the Solution Explorer, right-click the SimpleServerTaskWebApp_<language> project, and select Set as StartUp Project.
  9. Right-click Default.aspx and select Set As Start Page.
  10. Save the solution.
  11. Click the Debug drop-down menu and click Start Debugging. The custom task class library builds and is added to the Web project. The Default.aspx page displays a menu item to initialize the custom server task and the dialog box for the custom server task control.
  12. To add the custom task to the Visual Studio toolbox, follow the steps in the "Add the custom server task to the Visual Studio toolbox" section.
  13. To distribute the custom task to use in the Manager application, follow the steps in the "Add the custom task to Manager" section.

Add the custom server task to the Visual Studio toolbox
  1. In design mode for the default.aspx, right-click the toolbox, select Add Tab, and type a name for the new tab (for example, Custom Task Controls).
  2. Right-click the new tab and select Choose Items. The Choose Items dialog box appears.
  3. Click the Browse button, navigate to the location of the SimpleServerTask_CSharp.dll, and click Open. Two new controls are added to and selected in the Choose Items dialog box.
  4. Select the SimpleServerTask_CSharp check box, then click OK to close the dialog box. The new tab contains the custom server task control.

Add the custom task to Manager
  1. By default, the custom task project includes a key it uses to sign the class library. You can change this by generating your own key using the sn.exe utility included with the .NET software development kit (SDK). Open a Visual Studio command prompt and type, sn -k MyKeyPair.snk.
  2. In Visual Studio, right-click the class library project, select Properties in the context menu, click the Signing tab, select the Sign the assembly check box, and type the correct path to the key. This confirms that the key will be used to sign the custom server task assembly.
  3. Use the gacutil.exe utility included with the .NET SDK to add the assembly to the Global Assembly Cache (GAC). In the Visual Studio command prompt, type, gacutil -i SimpleServerTask_CSharp.dll.
  4. To add the custom task details to the Manager Tasks.xml file, in the App_Data folder for the Manager Web application (for example, C:\Inetpub\wwwroot\ArcGIS\Manager\App_Data), open the Tasks.xml file in a text editor, and add the following line in the <Tasks> tags: <Task Name="SimpleServerTask_CSharp" DisplayName="Simple ServerTask CSharp" Type="SimpleServerTask_CSharp.SimpleServerTask_CSharp, SimpleServerTask_CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b2d9a257d5f63add" TagPrefix="simpleServerTaskCS" />.
  5. Confirm the content of this entry, namely the version and public key token, by opening a Visual Studio command prompt and typing, gacutil -l SimpleServerTask_CSharp.
  6. Restart IIS by opening a Visual Studio command prompt and typing, iisreset. Manager can now recognize the new task and makes it available in the Tasks dialog box during Web application creation.

At run time
  1. Browse to the viewer uniform resource locator (URL), for example, http://localhost/Common_SimpleTask_CSharp/SimpleTaskWebApp_CSharp.
  2. The custom task control should be visible when the page loads. If not, click the menu to initialize the Tasks window.
  3. In the custom task, type a value in the text box and click the Execute button. The TaskResults control displays the results (in this case, the time on the Web server is returned with the text added in the text box as a child node).
  4. In Manager, login and create a Web application.
  5. During the process, in the Tasks window, select the Simple Task CSharp task and add it to the current list of tasks to be included in the Web application.
  6. Highlight the custom task in the Current Tasks window and click the Configure button.
  7. Set the name of the custom task window, the button text, and the background color of the control.
  8. Click OK, then click Finish. The Web application opens in a new browser window.
  9. Initialize the custom task in the Web application by expanding the Tasks panel and clicking the custom task menu.

Common_SimpleServerTask_CSharp\SimpleServerTask_CSharp.cs Custom task implementation code.
Common_SimpleServerTask_CSharp\SimpleServerTaskWebConfigurator_CSharp.cs Custom task implementation that provides a configurable dialog box in Manager.
Common_SimpleServerTask_CSharp\SimpleServerTaskDesigner_CSharp.cs Custom task implementation code that provides verbs to configure the custom task off the control in Visual Studio design time.
Common_SimpleServerTask_CSharp\ButtonTextEditorForm.cs Windows form initialized off a custom verb on the task in Visual Studio design time.
Common_SimpleServerTask_CSharp\ButtonTextEditor.cs Logic for Windows form initialized off a custom verb on the task in Visual Studio design time.
Common_SimpleServerTask_CSharp\Properties\AssemblyInfo.cs Assembly-specific information used when compiling the assembly. Note the custom tag prefix.
Common_SimpleServerTaskWebApp_CSharp\Default.aspx User interface (UI) for the Web application.
Common_SimpleServerTaskWebApp_CSharp\Default.aspx.cs Code behind the UI.
Download the C# files
Common_SimpleServerTask_VBNet\SimpleServerTask_VBNet.vb Custom task implementation code.
Common_SimpleServerTask_VBNet\SimpleServerTaskWebConfigurator_VBNet.vb Custom task implementation that provides a configurable dialog box in Manager.
Common_SimpleServerTask_VBNet\SimpleServerTaskDesigner_VBNet.vb Custom task implementation code that provides verbs to configure the custom task off the control in Visual Studio design time.
Common_SimpleServerTask_VBNet\ButtonTextEditorForm.vb Windows form initialized off a custom verb on the task in Visual Studio design time.
Common_SimpleServerTask_VBNet\ButtonTextEditor.vb Logic for Windows form initialized off a custom verb on the task in Visual Studio design time.
Common_SimpleServerTaskWebApp_VBNet\Default.aspx User interface (UI) for the Web application.
Common_SimpleServerTaskWebApp_VBNet\Default.aspx.vb Code behind the UI.
Download the VB.NET files

Download the files for all languages

See Also:

Creating a custom server task
Server task Manager integration