Readme_ServiceBrokerConfiguration
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 2005 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.
- .NET Framework SDK 2.0. You can obtain .NET Framework SDK free of charge. For more information, see Installing the .NET Framework SDK.
- SQL Server 2005 Database Engine.
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\90\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
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.
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.
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.
Build the Visual Studio Solution
Click Start, point to All Programs, point to Microsoft .NET Framework SDK v2.0, and then click SDK Command Prompt.
Locate the root folder of the sample. Type the following command for the default location:
[C#]
cd \Program Files\Microsoft SQL Server\90\``\Samples\Engine\Programmability\SMO\ServiceBrokerConfiguration\CS\
- Type the following to build the Visual Studio solution:
msbuild
Or, if you are using Visual Studio 2005, do the following:
- Open the \CS\ConfigurationComponent.sln solution file.
- Press F6 to build the solution.
Set up SQL Server sample database and sample XML schemas
Locate the \CS\Script folder.
Open and run setup.sql from within SQL Server Management Studio.
Set up SQL Server master keys (optional)
If you are setting up Remote Service Binding:
Locate the \CS\Script folder.
Open masterkey.sql from within SQL Server Management Studio.
Enter a password for the master database key in the CREATE MASTER KEY ENCRYPTION BY PASSWORD = statement.
Enter a password for the ssb_ConfigurationSample database key in the CREATE MASTER KEY ENCRYPTION BY PASSWORD = statement.
Run masterkey.sql.
Running the Sample
To run the sample
- The default location for the C# version is C:\Program Files\Microsoft SQL Server\90\Samples\SMO\ServiceBrokerConfiguration\CS\SampleApplication\bin\Debug\SampleApplication.exe.
To connect to a local SQL Server instance
Enter a server name in the Server Name field, or accept the default (local) server name.
Click Connect.
To configure the sample for a new database.
Click Options on the Objects tab.
Enter a ScriptPath, or accept the default path. The ScriptPath is used to export a script to a file.
Click Create. The Create button configures the sample, including setting the BaseUrn.
To create MessageTypes
Click New, and then click MessageType.
Enter ShippingRequest for the MessageType name.
Click Create to create the new MessageType, click New, and then click Message Type.
Enter ShippingAccept for the MessageType name.
Click Create to create the new MessageType, click New, and then click Message Type.
Enter ShippingComplete for MessageType name.
Click Create to create the new MessageType.
To create a contract
Click New, and then click Contract.
Select the MessageTypeMappings drop-down menu.
Select all MessageTypes created above.
Select Target for ShippingAccept and ShippingComplete MessageSource.
Close the MessageTypeMappings drop-down menu.
Enter Shipping for the contract name.
Click Create to create a new contact.
To create queues
Click New, and then click Queue.
Enter ClientQueue for the queue name.
Click Create to create the new queue, click New, and then click Queue.
Enter ServerQueue for queue name.
Click Create to create the new queue.
To create services without RemoteServiceBinding enabled
Click New, and then click Service.
Enter ClientService for the service name.
Select the ContractNames drop-down menu and select the Shipping contract.
Select the QueueName drop-down menu and select the ClientQueue queue.
Enter or select a ServiceOwnerName.
Click Create to create the new service, and then click New.
Enter ServerService for the service name.
Select the ContractNames drop-down and select the Shipping contract.
Select the QueueName drop-down menu and select the ServerQueue queue.
Enter or select a ServiceOwnerName.
Click Create to create the new service.
To create services with RemoteServiceBinding enabled
Click New, and then click Service.
Enter RemoteService for the service name.
Select the ContractNames drop-down menu and select the Shipping contract.
Set EnableRemoteService to true.
Select the QueueName drop-down menu and select the ClientQueue queue.
Enter or select a ServiceOwnerName.
Click Create to create the new service, and then click New.
To enable anonymous access for a Remote Service
Select RemoteService within the object tree.
Set AllowAnonymous to True.
Click Alter to alter the service.
To create a Target Instance Endpoint
Click New, and then click Target Instance Endpoint.
Enter a name, or accept the default name.
Click Create.
To set a script export path
Click the Object tab if this tab is not already active.
Click Options.
Enter a valid ScriptPath.
Click Create.
To export an object
Select an object within the objects tree.
Click Script then Export.
The object is exported to the ScriptPath set in Application Configuration.
To export a Service definition to a file
Select a service from within the Objects tree.
Click Script, and then click Export.
The service script is exported to the ScriptPath set in Application Configuration.
To drop an object
Select the object in the TreeView.
Click either Drop or Edit, Drop {ObjectName}.
To alter an object
Click the object in the Objects tree that you want to modify.
Modify the properties of that object.
Click Alter to alter the object.
To query data describing an object
Each object can output data describing the object to a Textbox and/or DataGrid.
Select an object in the TreeView.
Click Query.
Removing the Sample
To drop services
Click the ClientService node.
Drop the object.
Click the ServerService node.
Drop the object.
To drop queues
Click the ClientQueue node.
Drop the object.
Click the ServerQueue node.
Drop the object.
To drop contracts
Click the Shipping contract node.
Drop the object.
To drop MessageTypes
Click the ShippingRequest MessageType node.
Drop the object.
Click the ShippingAccept MessageType node.
Drop the object.
Click the ShippingComplete MessageType node.
Drop the object.
To drop a Target Instance Endpoint
Click a Target Instance Endpoint node.
Drop the object.