我在本地使用 Service Bus for Windows Service 1.0(客户端引用 Microsoft.ServiceBus.dll 1.8.0.0)
我正在尝试使 WCF 客户端和服务 NetMessagingBinding 示例正常工作。
我只是想向服务总线提交一条消息并将其发送到我的 wcf 服务。
目前我在提交时遇到问题,因为它找不到令牌提供者:
我有以下代码:
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();
}
//我的订单类如下所示:
[ServiceContract()]
public interface IOrderService
{
[OperationContract(IsOneWay = true)]
void ProcessOrder(Order order);
}
[DataContract()]
public class Order
{
[DataMember]
public Int64 OrderId;
}
但是当我尝试发送到队列时(client.ProcessOrder(order);)
我得到一个 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] DNS Lookup for "servicebusdefaultnamespace-sb.accesscontrol.windows.net" failed. The requested name is valid, but no data of the requested type was found
所以我想知道问题是什么:
sb://servicebusdefaultnamespace.servicebus.windows.net/Orders/是设置我的端点的正确 URI 吗?我问这个是因为当我得到 get-sbClientConfiguration - 我的连接字符串是:
Endpoint=sb://myPC/ServiceBusDefaultNamespace; StsEndpoint=https://myPC:9355/ServiceBusDefaultNamespace; RuntimePort=9354;ManagementPort=9355
还是我不能在 prem 上使用 sharedsecret 的事实?(我更喜欢使用这种身份验证方法)
谁能发现问题?
谢谢你的帮助