I have set up a Service bus 1.1 for windows server and trying to access it using the following code.
var sbUriList = new List<Uri>() { new UriBuilder { Scheme = "sb", Host = ServerFQDN, Path = ServiceNamespace }.Uri }; var httpsUriList = new List<Uri>() { new UriBuilder { Scheme = "https", Host = ServerFQDN, Path = ServiceNamespace, Port = HttpPort }.Uri }; NetworkCredential credential = new NetworkCredential("<User Name>", "<Password>", "<Domain>"); ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((s, cert, chain, ssl) => { return true; }); TokenProvider tokenProvider = TokenProvider.CreateOAuthTokenProvider(httpsUriList, credential); messageFactory = MessagingFactory.Create(sbUriList, tokenProvider); ServiceBusConnectionStringBuilder connBuilder = new ServiceBusConnectionStringBuilder(); connBuilder.ManagementPort = HttpPort; connBuilder.RuntimePort = TcpPort; connBuilder.Endpoints.Add(new UriBuilder() { Scheme = "sb", Host = ServerFQDN, Path = ServiceNamespace }.Uri); connBuilder.StsEndpoints.Add(new UriBuilder() { Scheme = "https", Host = ServerFQDN, Port = HttpPort, Path = ServiceNamespace }.Uri); namespaceManager = NamespaceManager.CreateFromConnectionString(connBuilder.ToString()); if (!namespaceManager.QueueExists(queuename)) { namespaceManager.CreateQueue(queuename); }this works fine if i run my code from a console application, but however if I put this in a windows service and run it under either a Local service or Local System the code throws the following exception while trying to check if the queue exists in the following line
namespaceManager.CreateQueue(queuename);
Unexpected exception : System.UnauthorizedAccessException: The remote server returned an error: (401) Unauthorized. Manage claim is required for this operation..TrackingId:5be1365e-b4ae-4555-b81b-dcbef96be9d0_GIE11LT32PD622,TimeStamp:4/19/2015 3:51:28 PM ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at Microsoft.ServiceBus.Messaging.ServiceBusResourceOperations.GetAsyncResult`1.<GetAsyncSteps>b__2d(GetAsyncResult`1 thisPtr, IAsyncResult r) at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result) --- End of inner exception stack trace ---Can someone help me understand how I can run my code as a windows service in either a "Local Service" or "Local System" and still be able to access the queue and post my messages.