Readme_ServiceBrokerConfiguration Sample

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

This sample works only with SQL Server 2005 and SQL Server 2008. It will not work with any version of SQL Server earlier than SQL Server 2005.

This sample shows how to create Service Broker objects by using SQL Server Management Objects (SMO). The sample is implemented because several Windows User Controls and classes necessary to create Service Broker objects.

The sample is targeted at a Microsoft .NET Framework developer who wants to learn how to use Service Broker SMO and learn how to create Windows User Controls to manage SQL Server objects. The core scenario is a Microsoft .NET Framework developer who is creating a custom Service Broker management application.

Samples are provided for educational purposes only. They are not intended to be used in a production environment and have not been tested in a production environment. Microsoft does not provide technical support for these samples. Sample applications and assemblies should not be connected to or used with your production SQL Server database or your report server without the permission of the system administrator.

Requirements

This sample requires that the following components are installed.

Location

If the code sample was installed to the default location, the sample is located in the following directory:

C:\Program Files\Microsoft SQL Server\100\Samples\Engine\Programmability\SMO\ServiceBrokerConfiguration

The C# solution for the code sample is located in the CS directory.

Building the Sample

If you have not already created a strong name key file, generate the key file using the following instructions.

To generate a strong name key file

  1. Open a Microsoft Visual Studio 2005 command prompt. Click Start, point to All Programs, point to Microsoft .NET Framework SDK 2.0, and then click SDK Command Prompt.

    -- or --

    Open a Microsoft .NET Framework command prompt. Click Start, point to All Programs, point to Microsoft .NET Framework SDK 2.0, and then click SDK Command Prompt.

  2. Use the change directory command (CD) to change the current directory of the command prompt window to the folder where the samples are installed.

    Note

    To determine the folder where samples are located, click the Start button, point to All Programs, point to Microsoft SQL Server, point to Documentation and Tutorials, and then click Samples Directory. If the default installation location was used, the samples are located in <system_drive>:\Program Files\Microsoft SQL Server\100\Samples.

  3. At the command prompt, run the following command to generate the key file:

    sn -k SampleKey.snk

    Important

    For more information about the strong-name key pair, see "Security Briefs: Strong Names and Security in the .NET Framework" in the .NET Development Center on MSDN.

If you are using the Microsoft .NET Framework SDK, do the following:

Build the Visual Studio Solution

  1. Click Start, point to All Programs, point to Microsoft .NET Framework SDK v2.0, and then click SDK Command Prompt.

  2. Locate the root folder of the sample. Type the following command for the default location:

  3. [C#]

cd \Program Files\Microsoft SQL Server\100\Samples\Engine\Programmability\SMO\ServiceBrokerConfiguration\CS\

  1. Type the following to build the Visual Studio solution:
    • msbuild

Or, if you are using Visual Studio 2005, do the following:

  1. Open the \CS\ConfigurationComponent.sln solution file.
  2. Press F6 to build the solution.

Set up SQL Server sample database and sample XML schemas

  1. Locate the \CS\Script folder.

  2. Open and run setup.sql from within SQL Server Management Studio.

If you are setting up Remote Service Binding:

Set up SQL Server master keys (optional)

  1. Locate the \CS\Script folder.

  2. Open masterkey.sql from within SQL Server Management Studio.

  3. Enter a password for the master database key in the CREATE MASTER KEY ENCRYPTION BY PASSWORD = statement.

  4. Enter a password for the ssb_ConfigurationSample database key in the CREATE MASTER KEY ENCRYPTION BY PASSWORD = statement.

  5. Run masterkey.sql.

Running the Sample

To run the sample

  1. The default location for the C# version is C:\Program Files\Microsoft SQL Server\100\Samples\SMO\ServiceBrokerConfiguration\CS\SampleApplication\bin\Debug\SampleApplication.exe.

To connect to a local SQL Server instance

  1. Enter a server name in the Server Name field, or accept the default (local) server name.

  2. Click Connect.

To configure the sample for a new database.

  1. Click Options on the Objects tab.

  2. Enter a ScriptPath, or accept the default path. The ScriptPath is used to export a script to a file.

  3. Click Create. The Create button configures the sample, including setting the BaseUrn.

To create MessageTypes

  1. Click New, and then click MessageType.

  2. Enter ShippingRequest for the MessageType name.

  3. Click Create to create the new MessageType, click New, and then click Message Type.

  4. Enter ShippingAccept for the MessageType name.

  5. Click Create to create the new MessageType, click New, and then click Message Type.

  6. Enter ShippingComplete for MessageType name.

  7. Click Create to create the new MessageType.

To create a contract

  1. Click New, and then click Contract.

  2. Select the MessageTypeMappings drop-down menu.

  3. Select all MessageTypes created above.

  4. Select Target for ShippingAccept and ShippingComplete MessageSource.

  5. Close the MessageTypeMappings drop-down menu.

  6. Enter Shipping for the contract name.

  7. Click Create to create a new contact.

To create queues

  1. Click New, and then click Queue.

  2. Enter ClientQueue for the queue name.

  3. Click Create to create the new queue, click New, and then click Queue.

  4. Enter ServerQueue for queue name.

  5. Click Create to create the new queue.

To create services without RemoteServiceBinding enabled

  1. Click New, and then click Service.

  2. Enter ClientService for the service name.

  3. Select the ContractNames drop-down menu and select the Shipping contract.

  4. Select the QueueName drop-down menu and select the ClientQueue queue.

  5. Enter or select a ServiceOwnerName.

  6. Click Create to create the new service, and then click New.

  7. Enter ServerService for the service name.

  8. Select the ContractNames drop-down and select the Shipping contract.

  9. Select the QueueName drop-down menu and select the ServerQueue queue.

  10. Enter or select a ServiceOwnerName.

  11. Click Create to create the new service.

To create services with RemoteServiceBinding enabled

  1. Click New, and then click Service.

  2. Enter RemoteService for the service name.

  3. Select the ContractNames drop-down menu and select the Shipping contract.

  4. Set EnableRemoteService to true.

  5. Select the QueueName drop-down menu and select the ClientQueue queue.

  6. Enter or select a ServiceOwnerName.

  7. Click Create to create the new service, and then click New.

To enable anonymous access for a Remote Service

  1. Select RemoteService within the object tree.

  2. Set AllowAnonymous to True.

  3. Click Alter to alter the service.

To create a Target Instance Endpoint

  1. Click New, and then click Target Instance Endpoint.

  2. Enter a name, or accept the default name.

  3. Click Create.

To set a script export path

  1. Click the Object tab if this tab is not already active.

  2. Click Options.

  3. Enter a valid ScriptPath.

  4. Click Create.

To export an object

  1. Select an object within the objects tree.

  2. Click Script then Export.

  3. The object is exported to the ScriptPath set in Application Configuration.

To export a Service definition to a file

  1. Select a service from within the Objects tree.

  2. Click Script, and then click Export.

  3. The service script is exported to the ScriptPath set in Application Configuration.

To drop an object

  1. Select the object in the TreeView.

  2. Click either Drop or Edit, Drop {ObjectName}.

To alter an object

  1. Click the object in the Objects tree that you want to modify.

  2. Modify the properties of that object.

  3. Click Alter to alter the object.

To query data describing an object

  1. Each object can output data describing the object to a Textbox and/or DataGrid.

  2. Select an object in the TreeView.

  3. Click Query.

Removing the Sample

To drop services

  1. Click the ClientService node.

  2. Drop the object.

  3. Click the ServerService node.

  4. Drop the object.

To drop queues

  1. Click the ClientQueue node.

  2. Drop the object.

  3. Click the ServerQueue node.

  4. Drop the object.

To drop contracts

  1. Click the Shipping contract node.

  2. Drop the object.

To drop MessageTypes

  1. Click the ShippingRequest MessageType node.

  2. Drop the object.

  3. Click the ShippingAccept MessageType node.

  4. Drop the object.

  5. Click the ShippingComplete MessageType node.

  6. Drop the object.

To drop a Target Instance Endpoint

  1. Click a Target Instance Endpoint node.

  2. Drop the object.