Service Bus The token has an invalid signature

Frazer picture Frazer · Nov 11, 2015 · Viewed 12.9k times · Source

I am trying to create a service bus relay based on this article

I get an error message Generic: InvalidSignature: The token has an invalid signature.

static void Main(string[] args)
{
        ServiceHost sh = new ServiceHost(typeof(ProblemSolver));

        sh.AddServiceEndpoint(
           typeof(IProblemSolver), new NetTcpBinding(),
           "net.tcp://tjservicebus.servicebus.windows.net/solver");

        Console.WriteLine("Add Binding End Point");

        var key = "MYKEY";

        sh.AddServiceEndpoint(
           typeof(IProblemSolver), new NetTcpRelayBinding(),
           ServiceBusEnvironment.CreateServiceUri("sb", "tjservicebus", "solver"))
            .Behaviors.Add(new TransportClientEndpointBehavior
            {
                TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", key)
            });

        sh.Open();

        Console.WriteLine("Press ENTER to close");
        Console.ReadLine();

        sh.Close();
    }

The error message appears at the point of sh.Open();

Can anyone help?

Answer

Dave C picture Dave C · Jul 9, 2018

I also had this error message and it turned out to be the same issue as Andy Zhang.

I deleted the service bus to test automated deployment and was still referencing the old SharedAccessKey in the connection string to connect but this had changed after redeployment.

We stored our connection string in Key Vault, so I had to change the connection string in there to resolve the issue.