I'm trying to connect to a windows service bus using HTTPS. Here is my app config setting:
<appSettings>
<add key="Microsoft.ServiceBus.ConnectionString" value="Endpoint=https://example-service.servicebus.windows.net/;SharedSecretIssuer=owner;SharedSecretValue=example-shared-secret-value"/>
</appSettings>
Here is the code that is trying to create the connection:
return SubscriptionClient.CreateFromConnectionString(ConnectionString, RequestTopicName,
SubscriptionName, ReceiveMode.ReceiveAndDelete);
However, it's not working, throwing this error:
Unable to create MessagingFactory using connection string. The provided URI scheme 'https' is invalid; expected 'sb'. See inner exception for details. Check your connection string and then try again. For more information please see http://go.microsoft.com/fwlink/?LinkID=249089
And the inner exception:
The provided URI scheme 'https' is invalid; expected 'sb'. at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessagingFactory..ctor(IEnumerable1 baseAddresses, NetMessagingTransportSettings settings)
at Microsoft.ServiceBus.Messaging.NetMessagingTransportSettings.Microsoft.ServiceBus.Messaging.ITransportSettings.BeginCreateFactory(IEnumerable
1 physicalUriAddresses, AsyncCallback callback, Object state)
at Microsoft.ServiceBus.Messaging.MessagingFactorySettings.OnBeginCreateFactory(IEnumerable1 uriAddresses, AsyncCallback callback, Object state)
at Microsoft.ServiceBus.Messaging.MessagingFactorySettings.BeginCreateFactory(IEnumerable
1 uriAddresses, AsyncCallback callback, Object state)
at Microsoft.ServiceBus.Messaging.MessagingFactory.CreateMessagingFactoryAsyncResult..ctor(MessagingFactorySettings settings, IEnumerable1 addresses, TimeSpan timeout, AsyncCallback callback, Object state)
at Microsoft.ServiceBus.Messaging.MessagingFactory.BeginCreate(IEnumerable
1 addresses, MessagingFactorySettings factorySettings, TimeSpan timeout, AsyncCallback callback, Object state)
at Microsoft.ServiceBus.Messaging.MessagingFactory.BeginCreate(IEnumerable1 addresses, MessagingFactorySettings factorySettings, AsyncCallback callback, Object state)
at Microsoft.ServiceBus.Messaging.MessagingFactory.BeginCreate(IEnumerable
1 addresses, TokenProvider tokenProvider, AsyncCallback callback, Object state)
at Microsoft.ServiceBus.Messaging.MessagingFactory.Create(IEnumerable1 addresses, TokenProvider tokenProvider)
at Microsoft.ServiceBus.Messaging.Configuration.KeyValueConfigurationManager.CreateFactory(IEnumerable
1 endpoints, IEnumerable`1 stsEndpoints, String operationTimeout, String issuerName, String issuerKey, String domain, String user, SecureString password)
If I change the connection string to use sb.example-service.servicebus.windows.net instead of https.example-service.servicebus.windows.net it will work, but I really need to use HTTPS instead of SB.
Any ideas why the client is expecting 'sb'? How can I configure the client to use 'https'.
Here is the solution: change the "https" part of the connection string back to "sb", that has to be "sb". Now add this line of code:
ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;