I am using Service Bus for Windows Service 1.0 on prem (clients are referencing Microsoft.ServiceBus.dll 1.8.0.0)
I am trying to get a WCF client and service NetMessagingBinding example working.
I simply want to submit a message to service bus and have it pumped out to my wcf service.
At the moment I have having problems submitting, as it cannot find the token provider:
I have the following code:
private const string Issuer = "myIssuerName";
private const string Key = "BBBBBB=";
private static readonly Uri ServiceBusEndpointAddress =
new Uri("{sb://servicebusdefaultnamespace.servicebus.windows.net/Orders/}");
private static void Main(string[] args)
{
//SetUp
var binding = new NetMessagingBinding();
var contract = ContractDescription.GetContract(typeof (IOrderService), typeof (OrderService));
var transportBehavior = new TransportClientEndpointBehavior();
transportBehavior.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(Issuer, Key);
var endpoint = new ServiceEndpoint(contract, binding,
new EndpointAddress(ServiceBusEndpointAddress.AbsoluteUri));
endpoint.Behaviors.Add(transportBehavior);
var host = new ServiceHost(typeof (OrderService), ServiceBusEndpointAddress);
host.AddServiceEndpoint(endpoint);
host.Open();
//send message to queue
var factory = new ChannelFactory<IOrderService>(endpoint);
var client = factory.CreateChannel();
var order = new Order();
order.OrderId = 42;
//this is where the exception is raised
client.ProcessOrder(order);
factory.Close();
Console.ReadLine();
}
//my order class looks like this:
[ServiceContract()]
public interface IOrderService
{
[OperationContract(IsOneWay = true)]
void ProcessOrder(Order order);
}
[DataContract()]
public class Order
{
[DataMember]
public Int64 OrderId;
}
But when I try to send to the queue (client.ProcessOrder(order);)
I get a 502:
unauthorisedaccessexception
The token provider was unable to provide a security token while accessing
'https://servicebusdefaultnamespace-sb.accesscontrol.windows.net/WRAPv0.9/'. Token
provider returned message: 'The remote name could not be resolved: 'servicebusdefaultnamespace-sb.accesscontrol.windows.net''.
The remote name could not be resolved: 'servicebusdefaultnamespace- sb.accesscontrol.windows.net'
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at Microsoft.ServiceBus.TokenProviderHelper.GetAccessTokenCore(Uri requestUri, String
appliesTo, String requestToken, String simpleAuthAssertionFormat, TimeSpan timeout,
String& expiresIn)
fiddler tells me:
[Fiddler] DNS Lookup for "servicebusdefaultnamespace-sb.accesscontrol.windows.net" failed. The requested name is valid, but no data of the requested type was found
So I was wondering what the problem is:
Is sb://servicebusdefaultnamespace.servicebus.windows.net/Orders/ the correct URI to set up my endpoint on?. I ask this because when I get get-sbClientConfiguration - my connection string is:
Endpoint=sb://myPC/ServiceBusDefaultNamespace; StsEndpoint=https://myPC:9355/ServiceBusDefaultNamespace; RuntimePort=9354;ManagementPort=9355
Or is it the fact that I cant use sharedsecret on prem? (I would prefer to use this authentication approach)
Can anyone spot the problem?
Thanks for your help