Created
August 22, 2012 21:10
-
-
Save rseroter/3429427 to your computer and use it in GitHub Desktop.
Example code for using Iron Foundry application service (Microsoft Service Bus)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public QueuingManager() | |
{ | |
var jss = new JavaScriptSerializer(); | |
dynamic data = jss.Deserialize<dynamic>(WebConfigurationManager.AppSettings["VCAP_SERVICES"]); | |
//set values | |
string sb_oauth = data["mssb-1.0"]["credentials"]["sb_oauth"]; // 4446 | |
string sb_runtime_address = data["mssb-1.0"]["credentials"]["sb_runtime_address"]; // 9354 | |
string userName = data["mssb-1.0"]["credentials"]["username"]; | |
string password = data["mssb-1.0"]["credentials"]["password"]; | |
//create SB uris | |
var rootAddressManagement = new Uri(sb_oauth); | |
var rootAddressRuntime = new Uri(sb_runtime_address); | |
//create NS manager | |
var nmSettings = new NamespaceManagerSettings(); | |
var nc = new NetworkCredential(userName, password); | |
nmSettings.TokenProvider = TokenProvider.CreateOAuthTokenProvider(new List<Uri>() { rootAddressManagement }, nc); | |
namespaceManager = new NamespaceManager(rootAddressManagement, nmSettings); | |
//create factory | |
var mfSettings = new MessagingFactorySettings(); | |
mfSettings.TokenProvider = TokenProvider.CreateOAuthTokenProvider(new List<Uri>() { rootAddressManagement }, nc); | |
messagingFactory = MessagingFactory.Create(rootAddressRuntime, mfSettings); | |
CreateQueue(); | |
} | |
private void CreateQueue() | |
{ | |
if (false == namespaceManager.QueueExists(QueueName)) | |
{ | |
namespaceManager.CreateQueue(QueueName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment