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're going to use—CSharp or VBNet—and copy the Common_SimpleServerTask_<language> folder to c:\inetpub\wwwroot. The <language> variable can be either 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 opens.
  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 Microsoft Visual Studio 2008 or 2010 and open the Common_SimpleServerTask_<language><vs_version> solution (for example, Common_SimpleServerTask_CSharp2008.sln) located in c:\inetpub\wwwroot\Common_SimpleServerTask_<language>. The <vs_version> references the Visual Studio version of the solution, either 2008 or 2010.
  8. In 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 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 below.
  13. To distribute the custom task for use in the Manager application, follow the steps in the Add the custom task to Manager section below.

Add the custom server task to the Visual Studio toolbox
  1. While in design mode of the default.aspx, right-click in 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 opens.
  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 and check the SimpleServerTask_CSharp 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 2008 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, check 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 a Visual Studio 2008 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 2008 or 2010 command prompt and typing: gacutil -l SimpleServerTask_CSharp
  6. Restart IIS by opening a Visual Studio 2008 or 2010 command prompt and typing: iisreset. Manager can now recognize the new task and will make 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 entered 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 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 for the Web application.
Common_SimpleServerTaskWebApp_CSharp\Default.aspx.cs Code behind the user interface.
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 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 for the Web application.
Common_SimpleServerTaskWebApp_VBNet\Default.aspx.vb Code behind the user interface.
Download the VB.NET files

Download the files for all languages

See Also:

Creating a custom server task
Server task Manager integration