Microsoft Service Bus on a Windows Workgroup

萝らか妹 提交于 2019-12-22 05:41:21

问题


I just started playing with Microsoft Service Bus. Now my personal challenge is that I'm doing this after hours, on my own time, etc, which means I am using VMs and Non-Domain pcs. These guys are all workgroup.

I've had pretty decent success, especially after I stumbled across this link: Microsoft Service Bus 1.0 unable to communicate with a server outside the client's domain

This guy provided a much needed boost to get me past being able to use the namespace to create queues, etc.

However, went I get to the QueueClient.Send() function, I'm still getting (and I paraphrased that a bit).

"The token provider was unable to provide a security token while accessing 'https://Windows2008Server:9355/ServiceBusDefaultNamespace/$STS/Windows/'. Token provider returned message: ''.

The same code from the link above is what I'm using for the message factory. So my question becomes, does anybody have any ideas on how to get past this send to work?

If I can get past this little issue then I can start seeing what Service Bus can really do.

Thanks so much!

Nick


Same issue as before, changed my code to be this:

        TokenProvider localUserTokenProvider = WindowsTokenProvider.CreateWindowsTokenProvider(connBuilder.StsEndpoints,new System.Net.NetworkCredential("LocalServer", "LocalPassword"));

        MessagingFactory messageFactory = MessagingFactory.Create(connBuilder.GetAbsoluteRuntimeEndpoints(), localUserTokenProvider);
        NamespaceManager namespaceManager = new NamespaceManager(connBuilder.GetAbsoluteManagementEndpoints(), localUserTokenProvider);

So, it looks like I still need to have the same account on both of them...


回答1:


I see. In that case, since you're using windows in both sides, you don't need the OAuthTokenProvider. You can use a Windows Token provider, just make sure of the following: - The credentials you're passing must exist in the server - Don't include any domain or workgroup information in the credential.

You need to configured it like this (the sample assumes you're using a config file for your connection strings):

TokenProvider localUserTokenProvider = WindowsTokenProvider.CreateWindowsTokenProvider(
            connBuilder.StsEndpoints,
            new System.Net.NetworkCredential (userName, password));

This page has more information on how to work 'offline' with Service Bus Server.




回答2:


If your client and your server are on different machines, you might have a certificate trust problem. You have to export the Service Bus Server CA from your server machine by using is installed, open the Service Bus for Windows Server PowerShell console and use the Get-SBAutoGeneratedCA cmdlet, and then import it in the Trusted Root Certification Authorities store of your client machine.

This page has more information on how to export / import them to enable the remote client scenario.




回答3:


I figured out what was going on, at least to an extent....

I have to hit the W2k8 server with the same credentials that I'm logged into my Win8 box (dev) with.

If I try to send in the parameters like this:

//namespaceManager.Settings.TokenProvider = TokenProvider.CreateOAuthTokenProvider(new Uri[] { new Uri("https://ServerName:9355") }, new NetworkCredential("ServerLocalUser", "ServerLocalUserPwd", "ServerName"));
//messageFactory.GetSettings().TokenProvider = TokenProvider.CreateOAuthTokenProvider(new Uri[] { new Uri("https://ServerName:9355") }, new NetworkCredential("ServerLocalUser", "ServerLocalPWD", "ServerName"));

Then it won't work. Any ideas why it's sending in my logged in credentials and not using the ServerLocalUser/Pwd/Name combination?

I found this by looking in the event logs...




回答4:


Here's what I did to get things to work.

I started out creating the same local user account on both my dev machine (Win8/Studio2012) and my server (Win2k8R2). I exported the client cert that's referenced above (2 or 3 times actually) and imported as needed. Once I got a good connection working, I started backing things out. Deleted the local account on my Win8 box, etc. Then it all started magically working.

A few things about my environ. I'm doing all of this with VMWare Fusion. (Yep Fusion). The VM Machines are all configured with NAT on the networking, no static IPs.

Don't know how, but it's working. I did just messages first. I figure if I can get messages working then I can go after Pub/Sub topics... That's next.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.ServiceBus;
    using Microsoft.ServiceBus.Messaging;
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    using System.Net.Security;
    using System.Diagnostics;
    using System.Security;

    namespace Test_Service_Bus
    {
        public static class Util
        {

            public static void SetCertificatePolicy()
            {
                ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;
            }

            private static bool RemoteCertificateValidate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
            {
                System.Console.WriteLine("Warning, trust any certificate");
                return true;
            }
        }

        class Program
        {

            static string ServerFQDN = "SVRNICK"; //System.Net.Dns.GetHostEntry(string.Empty).HostName;
            static int HttpPort = 9355;
            static int TcpPort = 9354;
            static string ServiceNameSpace = "ServiceBusDefaultNamespace";
            const string QueueName = "ServiceBusQueueSample";

            static void Main(string[] args)
            {
                SDKVersion();

            }


            static void SDKVersion()
            {

                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);

                TokenProvider localUserTokenProvider = WindowsTokenProvider.CreateWindowsTokenProvider(connBuilder.StsEndpoints, new System.Net.NetworkCredential("ServerLocalAcct", "ServerLocalPassword"));

                MessagingFactory messageFactory = MessagingFactory.Create(connBuilder.GetAbsoluteRuntimeEndpoints(), localUserTokenProvider);
                NamespaceManager namespaceManager = new NamespaceManager(connBuilder.GetAbsoluteManagementEndpoints(), localUserTokenProvider);

                NamespaceManager.CreateFromConnectionString(connBuilder.ToString());


                if (namespaceManager == null)
                {
                    Console.WriteLine("\nUnexpected error: NamespaceManager is NULL");
                    return;
                }

                Console.WriteLine("Checking if queue exists");
                if (namespaceManager.QueueExists(QueueName))
                {
                    Console.WriteLine("Queue exists, let's delete it so we can start over again");
                    namespaceManager.DeleteQueue(QueueName);
                }

                Console.WriteLine("And create a new queue");
                namespaceManager.CreateQueue(QueueName);



                // create a message client
                QueueClient myQueueClient = messageFactory.CreateQueueClient(QueueName);

                Console.WriteLine("Feeding messages");
                for (int i = 0; i < 1000; i++)
                {
                    if (i % 100 == 0)
                        Console.WriteLine("Messages sent: {0}", i.ToString());

                    // send to message broker
                    using (BrokeredMessage sendMessage = new BrokeredMessage("Hello world. " + i.ToString()))
                    {
                        sendMessage.Label = "Label_" + i.ToString(); ;
                        myQueueClient.Send(sendMessage);
                    }


                }

                BrokeredMessage receivedMessage = myQueueClient.Receive(TimeSpan.FromSeconds(5));

                while (receivedMessage != null)
                {
                    Console.WriteLine(string.Format("Message Received: Body={0}", receivedMessage.GetBody<string>()));
                    receivedMessage.Complete();

                    receivedMessage = myQueueClient.Receive(TimeSpan.FromSeconds(5));
                }

                // Close things down.
                Console.WriteLine("Closing down message");
                if (messageFactory != null)
                {
                    messageFactory.Close();
                }
            }
        }
    }


来源:https://stackoverflow.com/questions/15398665/microsoft-service-bus-on-a-windows-workgroup

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!