ea63b5d29a80c43ed2b4df77af6d68fb.ppt
- Количество слайдов: 103
Design Patterns, Practices, and Techniques with the Azure App. Fabric Service Bus Juval Lowy IDesign www. idesign. net © 2011 IDesign Inc. All rights reserved
Private IPs Discovery and registry Virtualization Proxy servers LB NAT Router H/W Firewall S/W Firewall Client Service Security IT in general …
1. Service connects and authenticates against relay Relay figures out how to best call back to service 2. Client connects and authenticates against relay 3. Client sends message to service 4. Relay forwards message to service Relay Service 2 3 Client 1 4 Service
public enum Discovery. Type { Public, Private } public class Service. Registry. Settings : IEndpoint. Behavior { public Service. Registry. Settings(); public Service. Registry. Settings(Discovery. Type discovery. Type); public Discovery. Type Discovery. Mode {get; set; } public string Display. Name {get; set; } }
IEndpoint. Behavior registery. Behavior = new Service. Registry. Settings(Discovery. Type. Public); Service. Host host = new Service. Host(typeof(My. Service)); foreach(Service. Endpoint endpoint in host. Description. Endpoints) { endpoint. Behaviors. Add(registery. Behavior); } host. Open();
public class Discoverable. Service. Host : Service. Host, IService. Bus. Properties { public Discoverable. Service. Host(object singleton. Instance, params Uri[] base. Addresses); public Discoverable. Service. Host(Type service. Type, params Uri[] base. Addresses); //More members }
public interface IService. Bus. Properties { Transport. Client. Endpoint. Behavior Credential {get; set; } Uri[] Addresses {get; } }
public class Net. Event. Relay. Binding : Net. Oneway. Relay. Binding {. . . }
Publisher Events Hub Subscriber
[Service. Contract] interface IMy. Events { [Operation. Contract(Is. One. Way = true)] void On. Event 1(); [Operation. Contract(Is. One. Way = true)] void On. Event 2(int number); [Operation. Contract(Is. One. Way = true)] void On. Event 3(int number, string text); }
public class Service. Bus. Events. Host : Discoverable. Service. Host { public Service. Bus. Events. Host(Type service. Type, Uri base. Address); public Service. Bus. Events. Host(Type service. Type, Uri[] base. Addresses); /*Additional constructors */ //Can optionally specify binding public virtual Net. Oneway. Relay. Binding {get; set; } public void Set. Binding(string binding. Config. Name); //Subscription management public void Subscribe(); public void Subscribe(Type contract. Type, string operation); public void Unsubscribe(Type contract. Type); public void Unsubscribe(Type contract. Type, string operation); }
[Service. Contract] interface IMy. Events { [Operation. Contract(Is. One. Way = true)] void On. Event 1(); [Operation. Contract(Is. One. Way = true)] void On. Event 2(int number); [Operation. Contract(Is. One. Way = true)] void On. Event 3(int number, string text); } class My. Subscriber: IMy. Events {. . . } string base. Address = "sb: //My. Namespace. servicebus. windows. net/"; Service. Bus. Events. Host host = new Service. Bus. Events. Host(typeof(My. Subscriber), base. Address); host. Open(); host. Subscribe(); host. Unsubscribe(typeof(IMy. Events), "On. Event 2"); host. Subscribe(); host. Unsubscribe();
public interface IDispatch. Operation. Selector { string Select. Operation(ref Message message); }
//Partial listing without error handling public class Service. Bus. Events. Host : Service. Bus. Host { //Managing the subscriptions Dictionary
public void Subscribe(Type contract. Type, string operation) { if(Subscriptions[contract. Type. Name]. Contains(operation) == false) { Subscriptions[contract. Type. Name]. Add(operation); } } public void Unsubscribe(Type contract. Type, string operation) { if(Subscriptions[contract. Type. Name]. Contains(operation)) { Subscriptions[contract. Type. Name]. Remove(operation); } } //Uses reflection to get all service contracts Type[] Get. Service. Contracts() {. . . }
class Event. Selector : IDispatch. Operation. Selector, IEndpoint. Behavior { readonly Dictionary
public abstract class Service. Bus. Events. Client. Base
class My. Events. Proxy : Service. Bus. Events. Client. Base
Discovery
[Service. Contract] public interface IService. Bus. Discovery { [Operation. Contract(Is. One. Way = true)] void Discovery. Request(string contract. Name, string contract. Namespace, Uri[] scopes. To. Match, Uri response. Address); }
[Service. Contract] public interface IService. Bus. Discovery. Callback { [Operation. Contract(Is. One. Way = true)] void Discovery. Response(Uri address, string contract. Namespace, Uri[] scopes); }
Client 3 Operation Event 1 IService. Bus. Discovery Requests Relay Service IService. Bus. Discovery. Callback 2 Service
public class Discoverable. Service. Host : Service. Host, IService. Bus. Properties { public Uri Discovery. Address {get; set; } public Net. Event. Relay. Binding Discovery. Request. Binding {get; set; } public Net. Oneway. Relay. Binding Discovery. Response. Binding {get; set; } public Discoverable. Service. Host(object singleton. Instance, params Uri[] base. Addresses); public Discoverable. Service. Host(Type service. Type, params Uri[] base. Addresses); }
public class Service. Bus. Discovery. Client : Client. Base
string service. Namespace = ". . . "; Service. Bus. Discovery. Client discovery. Client = new Service. Bus. Discovery. Client(service. Namespace, . . . ); Find. Criteria criteria = new Find. Criteria(typeof(IMy. Contract)); Find. Response discovered = discovery. Client. Find(criteria); discovery. Client. Close(); Endpoint. Address address = discovered. Endpoints[0]. Address; Binding binding = new Net. Tcp. Relay. Binding(); Channel. Factory
public static class Service. Bus. Discovery. Helper { public static Endpoint. Address Discover. Address
public static class Service. Bus. Discovery. Factory { public static T Create. Channel
[Service. Contract] public interface IService. Bus. Announcements { [Operation. Contract(Is. One. Way = true)] void On. Hello(Uri address, string contract. Namespace, Uri[] scopes); [Operation. Contract(Is. One. Way = true)] void On. Bye(Uri address, string contract. Namespace, Uri[] scopes); }
Client Operation Event 2 Announcements Relay Service IService. Bus. Announcements 1 Service
public class Discoverable. Service. Host : Service. Host, IService. Bus. Properties { public Uri Announcements. Address {get; set; } public Net. Oneway. Relay. Binding Announcements. Binding {get; set; } //More members }
[Service. Behavior(Use. Synchronization. Context = false, Instance. Context. Mode = Instance. Context. Mode. Single)] public class Service. Bus. Announcement. Sink
class My. Client { Addresses. Container
Buffers
Sender Reader
public class Buffered. Service. Bus. Host
[Service. Contract] interface IMy. Contract { [Operation. Contract(Is. One. Way = true)] void My. Method(int number); } class My. Contract. Client : Buffered. Service. Bus. Client
Service Buffer Client Service Response Buffer Response Service
Bonus Material
Service Bus Security
public static class Service. Bus. Helper { public static void Set. Service. Bus. Credentials(this Service. Host host, string secret); . . . } Service. Host host = new Service. Host(typeof(My. Service)); host. Service. Bus. Credentials("QV 3. . . 9 M 8="); host. Open();
public static partial class Service. Bus. Helper { public static void Set. Service. Bus. Credentials
public enum End. To. End. Security. Mode { None, Transport, Message, Transport. With. Message. Credential //Mixed }
Secure Insecure Client Service
Secure Insecure Client Service
public class Service. Bus. Host : Discoverable. Service. Host { public Service. Bus. Host(object singleton. Instance, params Uri[] base. Addresses); public Service. Bus. Host(Type service. Type, params Uri[] base. Addresses); public void Configure. Anonymous. Message. Security(); public void Configure. Anonymous. Message. Security(string service. Cert); public void Configure. Anonymous. Message. Security(string service. Cert, Store. Location location, Store. Name store. Name); public void Configure. Anonymous. Message. Security(Store. Location location, Store. Name store. Name, X 509 Find. Type find. Type, object find. Value); //More members }
Service. Bus. Host host = new Service. Bus. Host(typeof(My. Service)); host. Configure. Anonymous. Message. Security("My. Service. Cert"); host. Open();
public enum Service. Security { None, Anonymous, Business. To. Business, Internet, Intranet, Service. Bus } [Security. Behavior(Service. Security. Service. Bus)] class My. Service : IMy. Contract {. . . } Service. Host host = new Service. Host(typeof(My. Service)); host. Open();
public abstract class Service. Bus. Client. Base
[Service. Contract] interface IMy. Contract { [Operation. Contract] void My. Method(); } class My. Contract. Client : Service. Bus. Client. Base
Resources Connect. Share. Discuss. http: //northamerica. msteched. com Sessions On-Demand & Community Microsoft Certification & Training Resources www. microsoft. com/teched www. microsoft. com/learning Resources for IT Professionals Resources for Developers http: //microsoft. com/technet http: //microsoft. com/msdn


