//typeof(OnewayEnergyServiceOperations) private void InitService(string serviceNamespace, string issuerName, string issuerKey, string servicePath, ConnectivityMode onewayConnectivityMode, Type serviceType, bool usePassword) { ServiceBusEnvironment.SystemConnectivity.Mode = onewayConnectivityMode; // Host = new ServiceHost(serviceType, address); Host = new ServiceHost(serviceType); if (usePassword) { TransportClientEndpointBehavior behavior = ServiceBusHelper.GetUsernamePasswordBehavior(issuerName, issuerKey); Host.Description.Endpoints[0].Behaviors.Add(behavior); } ServiceUri = Host.Description.Endpoints[0].ListenUri.ToString(); ServiceRegistrySettings settings = new ServiceRegistrySettings(); settings.DiscoveryMode = DiscoveryType.Public; settings.DisplayName = ServiceUri; foreach (ServiceEndpoint se in Host.Description.Endpoints) { se.Behaviors.Add(settings); } Host.Open(); }
private void InitBindingInCode(string solutionName, string solutionPassword, string servicePath, ConnectivityMode onewayConnectivityMode, Type serviceType) { //ServiceBusEnvironment.OnewayConnectivity.Mode = onewayConnectivityMode; Uri address = ServiceBusEnvironment.CreateServiceUri("sb", solutionName, servicePath); ServiceUri = address.ToString(); Host = new ServiceHost(serviceType, address); ContractDescription contractDescription = ContractDescription.GetContract(typeof(IOnewayEnergyServiceOperations), typeof(OnewayEnergyServiceOperations)); ServiceEndpoint serviceEndPoint = new ServiceEndpoint(contractDescription); serviceEndPoint.Address = new EndpointAddress(ServiceUri); serviceEndPoint.Binding = new NetOnewayRelayBinding(); TransportClientEndpointBehavior behavior = ServiceBusHelper.GetUsernamePasswordBehavior(solutionName, solutionPassword); serviceEndPoint.Behaviors.Add(behavior); Host.Description.Endpoints.Add(serviceEndPoint); ServiceRegistrySettings settings = new ServiceRegistrySettings(); settings.DiscoveryMode = DiscoveryType.Public; settings.DisplayName = address.ToString(); foreach (ServiceEndpoint se in Host.Description.Endpoints) { se.Behaviors.Add(settings); } Host.Open(); }
public void ConstructionWorskWithMultipleContainerAndParents1() { // --- Arrange var settings = new ServiceRegistrySettings("other", new List <ServiceContainerSettings> { new ServiceContainerSettings("default", null, new List <MappingSettings> { new MappingSettings(typeof(ISampleService), typeof(ISampleService)) }), new ServiceContainerSettings("other", "default", new List <MappingSettings> { new MappingSettings(typeof(ISampleRepository), typeof(SampleRepository)), new MappingSettings(typeof(ISampleService), typeof(ISampleService)) }) }); // --- Act var registry = new ServiceRegistry(settings); // --- Assert registry.ContainerCount.ShouldEqual(2); registry["default"].ShouldNotBeNull(); registry["default"].GetRegisteredServices().ShouldHaveCountOf(1); registry["other"].ShouldNotBeNull(); registry["other"].Parent.ShouldBeSameAs(registry["default"]); registry["other"].GetRegisteredServices().ShouldHaveCountOf(2); registry["other"].ShouldBeSameAs(registry.DefaultContainer); }
public void DuplicateContainerNamesAreInTheExceptionMessage1() { // --- Arrange var settings = new ServiceRegistrySettings(null, new List <ServiceContainerSettings> { new ServiceContainerSettings("doublecontainer", null, new List <MappingSettings>()), new ServiceContainerSettings("doublecontainer", null, new List <MappingSettings>()), new ServiceContainerSettings("other1", null, new List <MappingSettings>()), new ServiceContainerSettings("other2", null, new List <MappingSettings>()), new ServiceContainerSettings("other2", null, new List <MappingSettings>()) }); // --- Act try { // ReSharper disable ObjectCreationAsStatement new ServiceRegistry(settings); // ReSharper restore ObjectCreationAsStatement Assert.Fail("Exception was expected"); } catch (DuplicatedContainerNameException ex) { ex.Message.ShouldContain("doublecontainer"); ex.Message.ShouldContain("other2"); ex.Message.ShouldNotContain("other1"); } }
private static void RunService() { Console.WriteLine("Server"); ServiceRegistrySettings registryBehavior = new ServiceRegistrySettings() { DiscoveryMode = DiscoveryType.Public, DisplayName = "Temperature Service" }; TransportClientEndpointBehavior credentialBehavior = new TransportClientEndpointBehavior(); credentialBehavior.CredentialType = TransportClientCredentialType.SharedSecret; credentialBehavior.Credentials.SharedSecret.IssuerName = issuerName; credentialBehavior.Credentials.SharedSecret.IssuerSecret = issuerKey; Uri serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", serviceBusNamespace, serviceName); using (ServiceHost serviceHost = new ServiceHost(typeof(TemperatureService), serviceUri)) { NetTcpRelayBinding binding = new NetTcpRelayBinding(); serviceHost.AddServiceEndpoint(typeof(ITemperatureContract), binding, serviceUri); serviceHost.Description.Endpoints[0].Behaviors.Add(credentialBehavior); serviceHost.Description.Endpoints[0].Behaviors.Add(registryBehavior); serviceHost.Open(); Console.WriteLine("Press Enter to exit."); Console.ReadLine(); } }
static void Main(string[] args) { string issuerName = "owner"; string issuerSecret = "y+4vWY/Ryoen5avmC4CPAYTHj/OpkUQ7eykVhxNjr2w="; TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior(); sharedSecretServiceBusCredential.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerSecret); // Cria o URI do serviço baseado no namespace do serviço Uri address = ServiceBusEnvironment.CreateServiceUri("sb", "spf-nspace", "EchoService"); // Cria o serviço host ServiceHost host = new ServiceHost(typeof(EchoService), address); //Cria o comportamento para o endpoint IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public); //Adiciona as credenciais do Service Bus a todos os endpoints configurados na configuração foreach (ServiceEndpoint endpoint in host.Description.Endpoints) { endpoint.Behaviors.Add(serviceRegistrySettings); endpoint.Behaviors.Add(sharedSecretServiceBusCredential); } // Abre o serviço. host.Open(); Console.WriteLine("Service address: " + address); Console.WriteLine("Press [Enter] to exit"); Console.ReadLine(); // Fecha o serviço. host.Close(); }
void EnableDiscovery() { Debug.Assert(State != CommunicationState.Opened); IEndpointBehavior registryBehavior = new ServiceRegistrySettings(DiscoveryType.Public); foreach (ServiceEndpoint endpoint in Description.Endpoints) { endpoint.Behaviors.Add(registryBehavior); } //Launch the service to monitor discovery requests DiscoveryRequestService discoveryService = new DiscoveryRequestService(Description.Endpoints.ToArray()); discoveryService.DiscoveryResponseBinding = DiscoveryResponseBinding; m_DiscoveryHost = new ServiceHost(discoveryService); m_DiscoveryHost.AddServiceEndpoint(typeof(IServiceBusDiscovery), DiscoveryRequestBinding, DiscoveryAddress.AbsoluteUri); TransportClientEndpointBehavior credentials = (this as IServiceBusProperties).Credential; m_DiscoveryHost.Description.Endpoints[0].Behaviors.Add(credentials); m_DiscoveryHost.Description.Endpoints[0].Behaviors.Add(registryBehavior); m_DiscoveryHost.Open(); }
static void Main(string[] args) { Console.Write("Initialising the Service Bus from Config "); TransportClientEndpointBehavior sharedSecretServicebusCredential = new TransportClientEndpointBehavior(); sharedSecretServicebusCredential.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider( ConfigurationSettings.AppSettings["IssuerName"], ConfigurationSettings.AppSettings["IssuerSecret"]); Uri address = ServiceBusEnvironment.CreateServiceUri("sb", ConfigurationSettings.AppSettings["ServiceNamespace"], "DriverService"); ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http; ServiceHost host = new ServiceHost(typeof(DriverService), address); IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public); foreach (ServiceEndpoint endpoint in host.Description.Endpoints) { endpoint.Behaviors.Add(serviceRegistrySettings); endpoint.Behaviors.Add(sharedSecretServicebusCredential); } host.Open(); Console.WriteLine("Service address: {0}", address); Console.WriteLine("Press any key to stop"); Console.ReadLine(); host.Close(); }
public ServiceBusHost(Type serviceType,params Uri[] baseAddresses) : base(serviceType,baseAddresses) { IEndpointBehavior registeryBehavior = new ServiceRegistrySettings(DiscoveryType.Public); foreach(ServiceEndpoint endpoint in Description.Endpoints) { endpoint.Behaviors.Add(registeryBehavior); } }
static void Main(string[] args) { ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http; Console.Write("Your Service Namespace: "); string serviceNamespace = Console.ReadLine(); Console.Write("Your Issuer Name: "); string issuerName = Console.ReadLine(); // The issuer secret is the Service Bus namespace management key. Console.Write("Your Issuer Secret: "); string issuerSecret = Console.ReadLine(); // Create the service URI based on the service namespace. Uri address = ServiceBusEnvironment.CreateServiceUri(Uri.UriSchemeHttps, serviceNamespace, "RemoteService"); Console.WriteLine("Service address: " + address); // Create the credentials object for the endpoint. TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior() { TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerSecret) }; // Create the binding object. WS2007HttpRelayBinding binding = new WS2007HttpRelayBinding(); binding.Security.Mode = EndToEndSecurityMode.Transport; // Create the service host reading the configuration. ServiceHost host = new ServiceHost(typeof(RemoteService)); host.AddServiceEndpoint(typeof(IServiceEndpointPlugin), binding, address); // Create the ServiceRegistrySettings behavior for the endpoint. IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public); // Add the Service Bus credentials to all endpoints specified in configuration. foreach (ServiceEndpoint endpoint in host.Description.Endpoints) { endpoint.Behaviors.Add(serviceRegistrySettings); endpoint.Behaviors.Add(sharedSecretServiceBusCredential); } // Open the service. host.Open(); Console.WriteLine("Press [Enter] to exit"); Console.ReadLine(); // Close the service. Console.Write("Closing the service host..."); host.Close(); Console.WriteLine(" done."); }
void EnableDiscovery() { Debug.Assert(State != CommunicationState.Opened); IEndpointBehavior registryBehavior = new ServiceRegistrySettings(DiscoveryType.Public); foreach(ServiceEndpoint endpoint in Description.Endpoints) { endpoint.Behaviors.Add(registryBehavior); } }
protected override object CreateBehavior() { ServiceRegistrySettings serviceRegistrySetting = new ServiceRegistrySettings() { DiscoveryMode = this.DiscoveryMode, DisplayName = this.DisplayName }; return(serviceRegistrySetting); }
static void Main() { string issuer = "owner"; string secret = "********* Enter your secret here **********"; TransportClientEndpointBehavior credential = new TransportClientEndpointBehavior(); credential.CredentialType = TransportClientCredentialType.SharedSecret; credential.Credentials.SharedSecret.IssuerName = issuer; credential.Credentials.SharedSecret.IssuerSecret = secret; ServiceRegistrySettings registeryBehavior = new ServiceRegistrySettings(DiscoveryType.Public); //////////////////////////////////////////////////////////////////////////// Console.WriteLine("Creating simple services..."); ServiceHost host1 = new ServiceHost(typeof(MyService)); host1.AddServiceEndpoint(typeof(IMyContract), new NetTcpRelayBinding(), @"sb://MyNamespace.servicebus.windows.net/MyService1"); host1.Description.Endpoints[0].Behaviors.Add(registeryBehavior); host1.Description.Endpoints[0].Behaviors.Add(credential); host1.Open(); ServiceHost host2 = new ServiceHost(typeof(MyService)); host2.AddServiceEndpoint(typeof(IMyContract), new NetTcpRelayBinding(), @"sb://MyNamespace.servicebus.windows.net/Top/MyService2"); host2.AddServiceEndpoint(typeof(IMyContract), new WS2007HttpRelayBinding(), @"https://MyNamespace.servicebus.windows.net/Top/Sub/MyService3"); host2.Description.Endpoints[0].Behaviors.Add(registeryBehavior); host2.Description.Endpoints[0].Behaviors.Add(credential); host2.Description.Endpoints[1].Behaviors.Add(registeryBehavior); host2.Description.Endpoints[1].Behaviors.Add(credential); host2.Open(); //////////////////////////////////////////////////////////////////////////// Console.WriteLine("Creating a buffer..."); string bufferAddress = "https://MyNamespace.servicebus.windows.net/MyBuffer/"; ServiceBusHelper.CreateBuffer(bufferAddress, secret); //////////////////////////////////////////////////////////////////////////// Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Press any key to close services and junctions"); Console.ReadLine(); host1.Close(); host2.Close(); ServiceBusHelper.DeleteBuffer(bufferAddress, secret); }
void EnableDiscovery() { Debug.Assert(State != CommunicationState.Opened); IEndpointBehavior registryBehavior = new ServiceRegistrySettings(DiscoveryType.Public); foreach (ServiceEndpoint endpoint in Description.Endpoints) { endpoint.Behaviors.Add(registryBehavior); } }
public override void Run() { try { string issuerName = "owner"; // ConfigurationSettings.AppSettings["UserName"]; string issuerKey = "wJBJaobUmarWn6kqv7QpaaRh3ttNVr3w1OjiotVEOL4="; // ConfigurationSettings.AppSettings["Password"]; string calcEndPoint = "sb://proazure.servicebus.windows.net/sample/calc/"; //ConfigurationSettings.AppSettings["EndPoint"]; string logEndPoint = "sb://proazure.servicebus.windows.net/sample/log/"; //ConfigurationSettings.AppSettings["EndPoint"]; ServiceBusLogger logger = new ServiceBusLogger(logEndPoint, issuerName, issuerKey); logger.Channel.WriteToLog(DateTime.UtcNow, "Worker Role", "Role Started"); Uri uri = new Uri(calcEndPoint); TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior(); sharedSecretServiceBusCredential.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerKey); host = new ServiceHost(typeof(CalculatorService), uri); logger.Channel.WriteToLog(DateTime.UtcNow, "Worker Role", "Service Host created"); ContractDescription contractDescription = ContractDescription.GetContract(typeof(ICalculator), typeof(CalculatorService)); ServiceEndpoint serviceEndPoint = new ServiceEndpoint(contractDescription); serviceEndPoint.Address = new EndpointAddress(uri); logger.Channel.WriteToLog(DateTime.UtcNow, "Worker Role", "Address created"); serviceEndPoint.Binding = new NetTcpRelayBinding(); logger.Channel.WriteToLog(DateTime.UtcNow, "Worker Role", "Binding created"); //Set the DiscoveryType to Public and Publish this in the Service Registry ServiceRegistrySettings serviceRegistrySettings = new ServiceRegistrySettings(); serviceRegistrySettings.DiscoveryMode = DiscoveryType.Public; serviceRegistrySettings.DisplayName = "My Calc Service"; serviceEndPoint.Behaviors.Add(sharedSecretServiceBusCredential); serviceEndPoint.Behaviors.Add(serviceRegistrySettings); logger.Channel.WriteToLog(DateTime.UtcNow, "Worker Role", "Added behaviors"); host.Description.Endpoints.Add(serviceEndPoint); host.Open(); logger.Channel.WriteToLog(DateTime.UtcNow, "Worker Role", "Host opened"); while (true) { Thread.Sleep(10000); logger.Channel.WriteToLog(DateTime.UtcNow, "Worker Role", "Working…"); } } catch (Exception ex) { Trace.WriteLine("Error starting role " + ex.Message, "Error"); } }
public void ConstructionWorksWithNoContainer() { // --- Arrange var settings = new ServiceRegistrySettings(null, new List <ServiceContainerSettings>()); // --- Act var registry = new ServiceRegistry(settings); // --- Assert registry.ContainerCount.ShouldEqual(1); registry.DefaultContainer.GetRegisteredServices().ShouldHaveCountOf(0); }
static void Main(string[] args) { // Determine the system connectivity mode based on the command line // arguments: -http, -tcp or -auto (defaults to auto) ServiceBusEnvironment.SystemConnectivity.Mode = GetConnectivityMode(args); Console.Write("Your Service Namespace: "); string serviceNamespace = Console.ReadLine(); Console.Write("Your Issuer Name: "); string issuerName = Console.ReadLine(); Console.Write("Your Issuer Secret: "); string issuerSecret = Console.ReadLine(); // create the service URI based on the service namespace Uri address = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, "EchoService"); // create the credentials object for the endpoint TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior(); sharedSecretServiceBusCredential.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerSecret); // individual listen URI suffix for this instance. string serviceInstanceId = Guid.NewGuid().ToString("N"); // create the service host ServiceHost host = new ServiceHost(typeof(EchoService)); // add the endpoint Uri instanceListenUri = new Uri(address, serviceInstanceId + "/"); ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(IEchoContract), new NetTcpRelayBinding(EndToEndSecurityMode.None, RelayClientAuthenticationType.RelayAccessToken), address, instanceListenUri); // create the ServiceRegistrySettings behavior for the endpoint IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public); // add the Service Bus credentials to all endpoints specified in configuration endpoint.Behaviors.Add(serviceRegistrySettings); endpoint.Behaviors.Add(sharedSecretServiceBusCredential); Console.WriteLine("Service address: " + endpoint.Address.Uri); Console.WriteLine("Listen address: " + endpoint.ListenUri); // open the service host.Open(); Console.WriteLine("Press [Enter] to exit"); Console.ReadLine(); // close the service host.Close(); }
static void Listen() { string serviceNamespace; string serviceIdentityName; string serviceIdentityKey; Console.WriteLine("Service Namespace:"); serviceNamespace = Console.ReadLine(); Console.WriteLine("Service Identity:"); serviceIdentityName = Console.ReadLine(); Console.WriteLine("Service Identity Key:"); serviceIdentityKey = Console.ReadLine(); TransportClientEndpointBehavior behavior = new TransportClientEndpointBehavior(); behavior.TokenProvider = SharedSecretTokenProvider.CreateSharedSecretTokenProvider(serviceIdentityName, serviceIdentityKey); var address = ServiceBusEnvironment.CreateServiceUri(Uri.UriSchemeHttps, serviceNamespace, "Demo/OneWayListener"); // binding var binding = new WS2007HttpRelayBinding(); binding.Security.Mode = EndToEndSecurityMode.Transport; var host = new ServiceHost(typeof (CRMOnlineOneWayListenerService)); var endPoint = host.AddServiceEndpoint(typeof (IServiceEndpointPlugin), binding, address); var serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Private); endPoint.Behaviors.Add(serviceRegistrySettings); endPoint.Behaviors.Add(behavior); try { // Open the service. host.Open(); Console.WriteLine("Host Open. Listening on endpoint Address: " + address); } catch (TimeoutException timeout) { Console.WriteLine("Opening the service timed out, details below:"); Console.WriteLine(timeout.Message); } Console.WriteLine("Press [Enter] to exit"); Console.ReadLine(); // Close the service. Console.Write("Closing the service host..."); host.Close(); Console.WriteLine(" done."); }
public void CircularContainerReferencesAreRecognized1() { // --- Arrange var settings = new ServiceRegistrySettings("other", new List <ServiceContainerSettings> { new ServiceContainerSettings("default", "other", new List <MappingSettings>()), new ServiceContainerSettings("other", "default", new List <MappingSettings>()) }); // --- Act // ReSharper disable ObjectCreationAsStatement new ServiceRegistry(settings); // ReSharper restore ObjectCreationAsStatement }
static void Main(string[] args) { Console.Write("Your Service Namespace: "); string serviceNamespace = Console.ReadLine(); Console.Write("Your Issuer Name: "); string issuerName = Console.ReadLine(); Console.Write("Your Issuer Secret: "); string issuerSecret = Console.ReadLine(); // create the service URI based on the service namespace Uri sbAddress = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, "Echo/Service"); Uri httpAddress = ServiceBusEnvironment.CreateServiceUri("http", serviceNamespace, "Echo/mex"); // create the credentials object for the endpoint TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior(); sharedSecretServiceBusCredential.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerSecret); // create the service host reading the configuration ServiceHost host = new ServiceHost(typeof(EchoService), sbAddress, httpAddress); // create the ServiceRegistrySettings behavior for the endpoint IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public); // add the Service Bus credentials to all endpoints specified in configuration foreach (ServiceEndpoint endpoint in host.Description.Endpoints) { endpoint.Behaviors.Add(serviceRegistrySettings); endpoint.Behaviors.Add(sharedSecretServiceBusCredential); } // open the service host.Open(); foreach (ChannelDispatcherBase channelDispatcherBase in host.ChannelDispatchers) { ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher; foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints) { Console.WriteLine("Listening at: {0}", endpointDispatcher.EndpointAddress); } } Console.WriteLine("Press [Enter] to exit"); Console.ReadLine(); host.Close(); }
public void UnknownDefaultContainerFails3() { // --- Arrange var settings = new ServiceRegistrySettings(null, new List <ServiceContainerSettings> { new ServiceContainerSettings("other", null, new List <MappingSettings>()), new ServiceContainerSettings("services", "default", new List <MappingSettings>()), }); // --- Act // ReSharper disable ObjectCreationAsStatement new ServiceRegistry(settings); // ReSharper restore ObjectCreationAsStatement }
public void DuplicateContainerNamesFail() { // --- Arrange var settings = new ServiceRegistrySettings("other", new List <ServiceContainerSettings> { new ServiceContainerSettings("other", null, new List <MappingSettings>()), new ServiceContainerSettings("other", null, new List <MappingSettings>()), }); // --- Act // ReSharper disable ObjectCreationAsStatement new ServiceRegistry(settings); // ReSharper restore ObjectCreationAsStatement }
public void ReadAndWriteWorksAsExpected2() { const string ROOT = "Root"; // --- Arrange var settings = new ServiceRegistrySettings(null, null); // --- Act var element = settings.WriteToXml(ROOT); var newSetting = new ServiceRegistrySettings(element); // --- Assert newSetting.Resolver.ShouldBeNull(); newSetting.DefaultContainer.ShouldBeNull(); newSetting.Containers.ShouldHaveCountOf(0); }
public void ReadAndWriteWorksAsExpected3() { const string CONTAINER_NAME = "containerName"; const string ROOT = "Root"; // --- Arrange var settings = new ServiceRegistrySettings(CONTAINER_NAME, null, new DefaultTypeResolver()); // --- Act var element = settings.WriteToXml(ROOT); var newSetting = new ServiceRegistrySettings(element); // --- Assert newSetting.Resolver.ShouldNotBeNull(); newSetting.DefaultContainer.ShouldEqual(CONTAINER_NAME); newSetting.Containers.ShouldHaveCountOf(0); }
static void Main(string[] args) { var sharedSecretServiceBusCredential = new TransportClientEndpointBehavior(); var serviceNamespace = "msswit2013relay"; var issuerName = "owner"; var issuerSecret = "IqyIwa7gNjBO89HT+3Vd1CcoBbyibvcv6Hd92J+FtPg="; sharedSecretServiceBusCredential.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider( issuerName, issuerSecret); Uri address = ServiceBusEnvironment.CreateServiceUri( "sb", serviceNamespace, "Service"); ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.AutoDetect; var host = new System.ServiceModel.ServiceHost( typeof(Service), address); IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public); foreach (ServiceEndpoint endpoint in host.Description.Endpoints) { endpoint.Behaviors.Add(serviceRegistrySettings); endpoint.Behaviors.Add(sharedSecretServiceBusCredential); } host.Open(); Console.WriteLine("Service address: " + address); Console.WriteLine("Press [Enter] to close"); Console.ReadLine(); host.Close(); }
void SetupServer(string serviceNamespace, string issuerName, string issuerSecret) { // create the service host reading the configuration host = new ServiceHost(typeof(ChatService), serviceUri); // create the ServiceRegistrySettings behavior for the endpoint IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public); // add the Service Bus credentials to all endpoints specified in configuration foreach (ServiceEndpoint endpoint in host.Description.Endpoints) { endpoint.Behaviors.Add(serviceRegistrySettings); endpoint.Behaviors.Add(sharedSecretServiceBusCredential); } // open the service host.Open(); }
static void Main(string[] args) { // Determine the system connectivity mode based on the command line // arguments: -http, -tcp or -auto (defaults to auto) ServiceBusEnvironment.SystemConnectivity.Mode = GetConnectivityMode(args); string serviceNamespace = ConfigurationManager.AppSettings["General.SBServiceNameSpace"]; string issuerName = ConfigurationManager.AppSettings["General.SBIssuerName"]; string issuerSecret = EncryptionUtility.Decrypt(ConfigurationManager.AppSettings["General.SBIssuerSecret"], ConfigurationManager.AppSettings["General.EncryptionThumbPrint"]); // create the service URI based on the service namespace Uri address = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, "SharePointProvisioning"); // create the credentials object for the endpoint TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior(); sharedSecretServiceBusCredential.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerSecret); // create the service host reading the configuration ServiceHost host = new ServiceHost(typeof(SharePointProvisioning), address); // create the ServiceRegistrySettings behavior for the endpoint IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public); // add the Service Bus credentials to all endpoints specified in configuration foreach (ServiceEndpoint endpoint in host.Description.Endpoints) { endpoint.Behaviors.Add(serviceRegistrySettings); endpoint.Behaviors.Add(sharedSecretServiceBusCredential); } // open the service host.OpenTimeout = TimeSpan.FromMinutes(15); host.CloseTimeout = TimeSpan.FromMinutes(15); host.Open(); Console.WriteLine("Service address: " + address); Console.WriteLine("Press [Enter] to exit"); Console.ReadLine(); // close the service host.Close(); }
static void Main(string[] args) { ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.AutoDetect; string serviceNamespace = "servicebus0810"; // Console.ReadLine(); string sasKey = " "; // namespace key // Create the credentials object for the endpoint. TransportClientEndpointBehavior sasCredential = new TransportClientEndpointBehavior(); sasCredential.TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", sasKey); // Create the service URI based on the service namespace. Uri address = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, "EchoService"); // Create the service host reading the configuration. ServiceHost host = new ServiceHost(typeof(EchoService), address); // Create the ServiceRegistrySettings behavior for the endpoint. IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public); // Add the Relay credentials to all endpoints specified in configuration. foreach (ServiceEndpoint endpoint in host.Description.Endpoints) { endpoint.Behaviors.Add(serviceRegistrySettings); endpoint.Behaviors.Add(sasCredential); } // Open the service. host.Open(); Console.WriteLine("Service address: " + address); Console.WriteLine("Insert e to exit"); string input = null; while (input != "e") { input = Console.ReadLine(); } // Close the service. host.Close(); }
public void GetServiceWorks2() { // --- Arrange var settings = new ServiceRegistrySettings("default", new List <ServiceContainerSettings> { new ServiceContainerSettings("default", null, new List <MappingSettings> { new MappingSettings(typeof(ISampleRepository), typeof(SampleRepository)), new MappingSettings(typeof(ISampleService), typeof(ISampleService)) }) }); var registry = new ServiceRegistry(settings); // --- Act var service = registry.GetService <ISampleRepository>(); // --- Assert service.ShouldBeOfType(typeof(SampleRepository)); }
public void ConstructionWorksWithNoExplicitDefaultContainer() { // --- Arrange var settings = new ServiceRegistrySettings(null, new List <ServiceContainerSettings> { new ServiceContainerSettings("default", null, new List <MappingSettings> { new MappingSettings(typeof(ISampleRepository), typeof(SampleRepository)), new MappingSettings(typeof(ISampleService), typeof(ISampleService)) }) }); // --- Act var registry = new ServiceRegistry(settings); // --- Assert registry.ContainerCount.ShouldEqual(1); registry["default"].ShouldNotBeNull(); registry["default"].ShouldBeSameAs(registry.DefaultContainer); }
private void InitService(string solutionName, string solutionPassword, string servicePath, Type serviceType, string protocol) { Uri address = ServiceBusEnvironment.CreateServiceUri(protocol, solutionName, servicePath); ServiceUri = address.ToString(); TransportClientEndpointBehavior behavior = ServiceBusHelper.GetUsernamePasswordBehavior(solutionName, solutionPassword); Host = new ServiceHost(serviceType, address); Host.Description.Endpoints[0].Behaviors.Add(behavior); ServiceRegistrySettings settings = new ServiceRegistrySettings(); settings.DiscoveryMode = DiscoveryType.Public; settings.DisplayName = address.ToString(); foreach (ServiceEndpoint se in Host.Description.Endpoints) { se.Behaviors.Add(settings); } Host.Open(); }
static void Main() { string issuer = "owner"; string secret = "******** Enter your secret here *******"; TransportClientEndpointBehavior creds = new TransportClientEndpointBehavior(); creds.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuer,secret); ServiceRegistrySettings registeryBehavior = new ServiceRegistrySettings(DiscoveryType.Public); //////////////////////////////////////////////////////////////////////////// Console.WriteLine("Creating simple services..."); ServiceHost host1 = new ServiceHost(typeof(MyService)); host1.AddServiceEndpoint(typeof(IMyContract),new NetTcpRelayBinding(),@"sb://mynamespace.servicebus.windows.net/MyService1"); host1.Description.Endpoints[0].Behaviors.Add(registeryBehavior); host1.Description.Endpoints[0].Behaviors.Add(creds); host1.Open(); ServiceHost host2 = new ServiceHost(typeof(MyService)); host2.AddServiceEndpoint(typeof(IMyContract),new NetTcpRelayBinding(),@"sb://mynamespace.servicebus.windows.net/Top/MyService2"); host2.AddServiceEndpoint(typeof(IMyContract),new WS2007HttpRelayBinding(),@"https://mynamespace.servicebus.windows.net/Top/Sub/MyService3"); host2.Description.Endpoints[0].Behaviors.Add(registeryBehavior); host2.Description.Endpoints[0].Behaviors.Add(creds); host2.Description.Endpoints[1].Behaviors.Add(registeryBehavior); host2.Description.Endpoints[1].Behaviors.Add(creds); host2.Open(); //////////////////////////////////////////////////////////////////////////// Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Press any key to close services and junctions"); Console.ReadLine(); host1.Close(); host2.Close(); ServiceBusHelper.DeleteBuffer(bufferAddress,secret); }
static void Main(string[] args) { // HACK: 3 constantes adicionais, para se poderem alterar 'a vontade const string serviceSheme = "sb"; const string serviceNamespace = "cmfservicebusnamespace"; // "catiavaz"; const string servicePath = "EchoService"; string issuerName = "owner"; // "owner"; string issuerSecret = "CZzrHKiB2QjRCJjBC5kFwXVrWV4w5qpBphpwpt43Tmw="; // "MYKEY"; TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior(); sharedSecretServiceBusCredential.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerSecret); // Cria o URI do serviço baseado no namespace do serviço Uri address = ServiceBusEnvironment.CreateServiceUri(serviceSheme, serviceNamespace, servicePath); // Cria o serviço host ServiceHost host = new ServiceHost(typeof(EchoService), address); //Cria o comportamento para o endpoint IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public); //Adiciona as credenciais do Service Bus a todos os endpoints configurados na configuração foreach (ServiceEndpoint endpoint in host.Description.Endpoints) { endpoint.Behaviors.Add(serviceRegistrySettings); endpoint.Behaviors.Add(sharedSecretServiceBusCredential); } // Abre o serviço. host.Open(); Console.WriteLine("Service address: " + address); // sb://cmfservicebusnamespace.servicebus.windows.net/EchoService/ Console.WriteLine("Press [Enter] to exit"); Console.ReadLine(); // Fecha o serviço. host.Close(); }
private void InitNetTcpRelayServer() { try { string issuerName = tsSolutionName.Text; string issuerKey = tsSolutionPassword.Text; string serviceNamespaceDomain = tsSolutionToConnect.Text; TransportClientEndpointBehavior behavior = new TransportClientEndpointBehavior(); behavior.TokenProvider = SharedSecretTokenProvider.CreateSharedSecretTokenProvider(issuerName, Encoding.ASCII.GetBytes(issuerKey)); Uri address = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespaceDomain, ServiceBusHelper.GetGatewayServicePath(tsGatewayId.Text)); //For WS2207HttpRelayBinding // Uri address = ServiceBusEnvironment.CreateServiceUri("http", serviceNamespaceDomain, ServiceBusHelper.GetGatewayServicePath(tsGatewayId.Text)); serviceUri = address.ToString(); server = new ServiceHost(this, address); server.Description.Endpoints[0].Behaviors.Add(behavior); ServiceRegistrySettings settings = new ServiceRegistrySettings(); settings.DiscoveryMode = DiscoveryType.Public; settings.DisplayName = address.ToString(); foreach (ServiceEndpoint se in server.Description.Endpoints) { se.Behaviors.Add(settings); } server.Open(); AddLog("Gateway Server Running with ServiceUri:" + address.ToString()); AddLog("Service registered for public discovery."); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void RegisterWorks() { // --- Arrange var settings = new ServiceRegistrySettings("default", new List <ServiceContainerSettings> { new ServiceContainerSettings("default", null, new List <MappingSettings> { new MappingSettings(typeof(ISampleRepository), typeof(SampleRepository)), }) }); var registry = new ServiceRegistry(settings); // --- Act var before = registry.GetRegisteredServices(); registry.Register(typeof(ISampleService), typeof(SampleService)); var after = registry.GetRegisteredServices(); // --- Assert before.ShouldHaveCountOf(1); after.ShouldHaveCountOf(2); }
/// <summary> /// Prompts for required information and hosts a service until the user ends the /// session. /// </summary> public void Run() { //<snippetTwoWayListener1> ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http; Console.Write("Enter your Azure service namespace: "); string serviceNamespace = Console.ReadLine(); // The service namespace issuer name to use. If one hasn't been setup // explicitly it will be the default issuer name listed on the service // namespace. Console.Write("Enter your service namespace issuer name: "); string issuerName = Console.ReadLine(); // Issuer secret is the Windows Azure Service Bus namespace current management key. Console.Write("Enter your service namespace issuer key: "); string issuerKey = Console.ReadLine(); // Input the same path that was specified in the Service Bus Configuration dialog // when registering the Azure-aware plug-in with the Plug-in Registration tool. Console.Write("Enter your endpoint path: "); string servicePath = Console.ReadLine(); // Leverage the Azure API to create the correct URI. Uri address = ServiceBusEnvironment.CreateServiceUri( Uri.UriSchemeHttps, serviceNamespace, servicePath); Console.WriteLine("The service address is: " + address); // Create the shared secret credentials object for the endpoint matching the // Azure access control services issuer var sharedSecretServiceBusCredential = new TransportClientEndpointBehavior() { TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerKey) }; // Using an HTTP binding instead of a SOAP binding for this endpoint. WS2007HttpRelayBinding binding = new WS2007HttpRelayBinding(); binding.Security.Mode = EndToEndSecurityMode.Transport; // Create the service host for Azure to post messages to. ServiceHost host = new ServiceHost(typeof(TwoWayEndpoint)); host.AddServiceEndpoint(typeof(ITwoWayServiceEndpointPlugin), binding, address); // Create the ServiceRegistrySettings behavior for the endpoint. var serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public); // Add the service bus credentials to all endpoints specified in configuration. foreach (var endpoint in host.Description.Endpoints) { endpoint.Behaviors.Add(serviceRegistrySettings); endpoint.Behaviors.Add(sharedSecretServiceBusCredential); } // Begin listening for messages posted to Azure. host.Open(); Console.WriteLine(Environment.NewLine + "Listening for messages from Azure" + Environment.NewLine + "Press [Enter] to exit"); // Keep the listener open until Enter is pressed. Console.ReadLine(); Console.Write("Closing the service host..."); host.Close(); Console.WriteLine(" done."); //</snippetTwoWayListener1> }
static void Main(string[] args) { ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http; // The one specified when creating the azure bus Console.Write("Enter your Azure service namespace: "); string serviceNamespace = Console.ReadLine(); // The shared access key policy name Console.Write("Enter your shared access policy name: "); string sharedAccesKeyName = Console.ReadLine(); // The primary of they access key policy specificied above Console.Write("Enter your shared access policy key: "); string sharedAccessKey = Console.ReadLine(); // Input the same path that was specified in the Service Bus Configuration dialog // when registering the Azure-aware plug-in with the Plug-in Registration tool. Console.Write("Enter your endpoint path: "); string servicePath = Console.ReadLine(); // Leverage the Azure API to create the correct URI. Uri address = ServiceBusEnvironment.CreateServiceUri( Uri.UriSchemeHttps, serviceNamespace, servicePath); Console.WriteLine("Service address: " + address); // Create the credentials object for the endpoint. TransportClientEndpointBehavior sharedAccessServiceBusCredential = new TransportClientEndpointBehavior() { TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(sharedAccesKeyName, sharedAccessKey) }; // Create the binding object. WS2007HttpRelayBinding binding = new WS2007HttpRelayBinding(); binding.Security.Mode = EndToEndSecurityMode.Transport; // Create the service host reading the configuration. ServiceHost host = new ServiceHost(typeof(RemoteService)); host.AddServiceEndpoint(typeof(IServiceEndpointPlugin), binding, address); // Create the ServiceRegistrySettings behavior for the endpoint. IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public); // Add the Service Bus credentials to all endpoints specified in configuration. foreach (ServiceEndpoint endpoint in host.Description.Endpoints) { endpoint.Behaviors.Add(serviceRegistrySettings); endpoint.Behaviors.Add(sharedAccessServiceBusCredential); } // Open the service. host.Open(); Console.WriteLine("Press [Enter] to exit"); Console.ReadLine(); // Close the service. Console.Write("Closing the service host..."); host.Close(); Console.WriteLine(" done."); }
void EnableDiscovery() { Debug.Assert(State != CommunicationState.Opened); IEndpointBehavior registryBehavior = new ServiceRegistrySettings(DiscoveryType.Public); foreach(ServiceEndpoint endpoint in Description.Endpoints) { endpoint.Behaviors.Add(registryBehavior); } //Launch the service to monitor discovery requests DiscoveryRequestService discoveryService = new DiscoveryRequestService(Description.Endpoints.ToArray()); discoveryService.DiscoveryResponseBinding = DiscoveryResponseBinding; m_DiscoveryHost = new ServiceHost(discoveryService); m_DiscoveryHost.AddServiceEndpoint(typeof(IServiceBusDiscovery),DiscoveryRequestBinding,DiscoveryAddress.AbsoluteUri); TransportClientEndpointBehavior credentials = (this as IServiceBusProperties).Credential; m_DiscoveryHost.Description.Endpoints[0].Behaviors.Add(credentials); m_DiscoveryHost.Description.Endpoints[0].Behaviors.Add(registryBehavior); m_DiscoveryHost.Open(); }