2013-08-03 42 views
5

Tôi đang sử dụng dịch vụ xe buýt cho Windows Service 1.0 dữ liệu tại chỗ (khách hàng đang tham chiếu Microsoft.ServiceBus.dll 1.8.0.0)dịch vụ 1.0 và WCF NetMessagingBinding - nhà cung cấp thẻ không thể cung cấp bảo mật thẻ

tôi đang cố gắng để có được một khách hàng WCF và dịch vụ NetMessagingBinding ví dụ làm việc.

Tôi chỉ muốn gửi tin nhắn đến xe buýt dịch vụ và đã bơm nó ra dịch vụ wcf của tôi.

Tại thời điểm này tôi đã gặp vấn đề nộp, vì nó không thể tìm thấy các nhà cung cấp mã thông báo:

Tôi có đoạn mã sau:

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

// lớp đơn hàng của tôi trông như thế này:

[ServiceContract()] 
public interface IOrderService 
{ 
    [OperationContract(IsOneWay = true)] 
    void ProcessOrder(Order order); 
} 

[DataContract()] 
public class Order 
{ 
    [DataMember] 
    public Int64 OrderId; 
} 

Nhưng khi tôi cố gắng gửi đến hàng đợi (client.ProcessOrder (order);)

tôi nhận được một 502: cáy

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) 

nói với tôi:

[Fiddler] DNS Lookup for "servicebusdefaultnamespace-sb.accesscontrol.windows.net" failed. The requested name is valid, but no data of the requested type was found       

Vì vậy, tôi đã tự hỏi vấn đề là gì:

  1. sb: //servicebusdefaultnamespace.servicebus. windows.net/Orders/ URI chính xác để thiết lập điểm cuối của tôi trên ?. Tôi hỏi vì điều này khi tôi nhận get-sbClientConfiguration - chuỗi kết nối của tôi là:

    Endpoint=sb://myPC/ServiceBusDefaultNamespace; 
        StsEndpoint=https://myPC:9355/ServiceBusDefaultNamespace; 
        RuntimePort=9354;ManagementPort=9355 
    
  2. Hoặc là nó thực tế là tôi không thể sử dụng sharedsecret liệu tại chỗ? (Tôi muốn sử dụng phương thức xác thực này)

Có ai phát hiện sự cố không?

Cảm ơn sự giúp đỡ của bạn

Trả lời

3

Chỉ hoạt động!

Có hai điều sai: Tôi nghĩ rằng bằng cách thêm không gian tên servicebus.windows.net tôi đã cố gắng gọi ra nhà cung cấp mã thông báo azure.

  1. Vì vậy, thay vào đó tôi đã tạo ra một windowsTokenProvider, và URI là sts quyết

    https://mypc:9355/ServiceBusDefaultNamespace 
    

bạn có thể tìm thấy điều này bằng cách chạy PowerShell này cmd:

get-sbclientconfiguration 
  1. Sau đó, tôi đã thay đổi địa chỉ điểm cuối Dịch vụ của mình thành: (dropp ing servicebus.windows.net)

    sb://mypcname/servicebusdefaultnamespace/Orders 
    

và bây giờ được xuất bản để dịch vụ xe buýt.

Đây là mã cuối cùng:

private static void Main(string[] args) 
    { 

     var ServiceBusEndpointAddress = new Uri("sb://mypc/servicebusdefaultnamespace/Orders"); 

     //SetUp 
     var binding = new NetMessagingBinding(); 
     var contract = ContractDescription.GetContract(typeof (IOrderService), typeof (OrderService)); 
     var uri = new Uri("https://mypc:9355/ServiceBusDefaultNamespace"); 
     var uris = new List<Uri> { uri }; 
     // Get credentials as Endpoint behavior 
     var securityBehavior = new TransportClientEndpointBehavior 
      { 
       TokenProvider = TokenProvider.CreateWindowsTokenProvider(uris) 
      }; 

     var endpoint = new ServiceEndpoint(contract, binding, 
              new EndpointAddress(ServiceBusEndpointAddress)); 
     endpoint.Behaviors.Add(securityBehavior); 

     var host = new ServiceHost(typeof(OrderService), uri); 
     host.AddServiceEndpoint(endpoint); 

     host.Open(); 


     //Client 

     var factory = new ChannelFactory<IOrderService>(endpoint); 
     var client = factory.CreateChannel(); 

     var order = new Order(); 
     order.OrderId = 42; 

     client.ProcessOrder(order); 
     factory.Close(); 

     Console.ReadLine(); 
    } 
Các vấn đề liên quan