private void InitNetEventRelayClient() { string issuerName = tsSolutionName.Text; string issuerKey = tsSolutionPassword.Text; string serviceNamespaceDomain = tsSolutionToConnect.Text; try { TransportClientEndpointBehavior behavior = new TransportClientEndpointBehavior(); string token = SharedSecretTokenProvider.ComputeSimpleWebTokenString(issuerName, issuerKey); behavior.TokenProvider = SimpleWebTokenProvider.CreateSimpleWebTokenProvider(token); Uri serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespaceDomain, "Gateway/MulticastService/"); // netEventRelayChannelFactory = new ChannelFactory<IMulticastGatewayChannel>("RelayMulticastEndpoint", new EndpointAddress(serviceUri)); netEventRelayChannelFactory = new ChannelFactory <IMulticastGatewayChannel>("RelayMulticastEndpoint"); netEventRelayChannelFactory.Endpoint.Behaviors.Add(behavior); netEventRelayChannel = netEventRelayChannelFactory.CreateChannel(); netEventRelayChannel.Open(); SendONLINEValue(); AddLog("Connected to " + netEventRelayChannelFactory.Endpoint.Address.Uri.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private TransportClientEndpointBehavior GetACSSecurity(string issuerName, string issuerKey) { TransportClientEndpointBehavior behavior = new TransportClientEndpointBehavior(); behavior.TokenProvider = SharedSecretTokenProvider.CreateSharedSecretTokenProvider(issuerName, Encoding.ASCII.GetBytes(issuerKey)); return(behavior); }
public static TransportClientEndpointBehavior GetUsernamePasswordBehavior(string issuerName, string issuerKey) { TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior(); sharedSecretServiceBusCredential.TokenProvider = SharedSecretTokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerKey); return(sharedSecretServiceBusCredential); }
static void Main(string[] args) { try { string serviceNamespaceDomain = ServiceBusHelper.GetServiceBusSolutionName(); string issuerName = "owner"; string issuerSecret = "wJBJaobUmarWn6kqv7QpaaRh3ttNVr3w1OjiotVEOL4="; ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.AutoDetect; TransportClientEndpointBehavior relayCredentials = new TransportClientEndpointBehavior(); relayCredentials.TokenProvider = SharedSecretTokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerSecret); Uri serviceAddress = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespaceDomain, "Gateway/MulticastService/"); ServiceHost host = new ServiceHost(typeof(MulticastGatewayOperations), serviceAddress); host.Description.Endpoints[0].Behaviors.Add(relayCredentials); host.Open(); Console.WriteLine("ServiceUri:" + serviceAddress.ToString()); Console.WriteLine("Service registered for public discovery."); NetEventRelayBinding binding = host.Description.Endpoints[0].Binding as NetEventRelayBinding; if (binding != null) { Console.WriteLine("Scheme:" + binding.Scheme); Console.WriteLine("Security Mode:" + binding.Security.Mode); Console.WriteLine("Security RelayAuthType:" + binding.Security.RelayClientAuthenticationType.ToString()); Console.WriteLine("Security Transport.ProtectionLevel:" + binding.Security.Transport.ProtectionLevel.ToString()); } Console.WriteLine("Press [Enter] to exit"); Console.ReadLine(); host.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
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); } }
private static bool FactoryEquals(MessagingFactory factory1, MessagingFactory factory2) { bool flag; bool flag1; bool flag2; bool flag3; bool flag4; MessagingFactorySettings settings = factory1.GetSettings(); SharedSecretTokenProvider tokenProvider = settings.TokenProvider as SharedSecretTokenProvider; SharedAccessSignatureTokenProvider sharedAccessSignatureTokenProvider = settings.TokenProvider as SharedAccessSignatureTokenProvider; WindowsTokenProvider windowsTokenProvider = settings.TokenProvider as WindowsTokenProvider; OAuthTokenProvider oAuthTokenProvider = settings.TokenProvider as OAuthTokenProvider; MessagingFactorySettings messagingFactorySetting = factory2.GetSettings(); SharedSecretTokenProvider sharedSecretTokenProvider = messagingFactorySetting.TokenProvider as SharedSecretTokenProvider; SharedAccessSignatureTokenProvider tokenProvider1 = messagingFactorySetting.TokenProvider as SharedAccessSignatureTokenProvider; WindowsTokenProvider windowsTokenProvider1 = messagingFactorySetting.TokenProvider as WindowsTokenProvider; OAuthTokenProvider oAuthTokenProvider1 = messagingFactorySetting.TokenProvider as OAuthTokenProvider; if (settings.OperationTimeout != messagingFactorySetting.OperationTimeout) { return(false); } if (settings.TransportType != messagingFactorySetting.TransportType) { return(false); } if (tokenProvider != null || sharedSecretTokenProvider != null) { flag = (tokenProvider == null ? false : sharedSecretTokenProvider != null); } else { flag = true; } bool flag5 = flag; if (windowsTokenProvider != null || windowsTokenProvider1 != null) { flag1 = (windowsTokenProvider == null ? false : windowsTokenProvider1 != null); } else { flag1 = true; } bool flag6 = flag1; if (oAuthTokenProvider != null || oAuthTokenProvider1 != null) { flag2 = (oAuthTokenProvider == null ? false : oAuthTokenProvider1 != null); } else { flag2 = true; } bool flag7 = flag2; if (sharedAccessSignatureTokenProvider != null || tokenProvider1 != null) { flag3 = (sharedAccessSignatureTokenProvider == null ? false : tokenProvider1 != null); } else { flag3 = true; } bool flag8 = flag3; if (!flag5 || !flag6 || !flag7 || !flag8) { return(false); } if (tokenProvider != null && sharedSecretTokenProvider != null && (tokenProvider.IssuerName != sharedSecretTokenProvider.IssuerName || !tokenProvider.IssuerSecret.SequenceEqual <byte>(sharedSecretTokenProvider.IssuerSecret) || tokenProvider.IsWebTokenSupported != sharedSecretTokenProvider.IsWebTokenSupported)) { return(false); } if (sharedAccessSignatureTokenProvider != null && tokenProvider1 != null) { if (sharedAccessSignatureTokenProvider.encodedSharedAccessKey != null || tokenProvider1.encodedSharedAccessKey != null) { flag4 = (sharedAccessSignatureTokenProvider.encodedSharedAccessKey == null ? false : tokenProvider1.encodedSharedAccessKey != null); } else { flag4 = true; } bool flag9 = flag4; if (sharedAccessSignatureTokenProvider.keyName != tokenProvider1.keyName || sharedAccessSignatureTokenProvider.tokenTimeToLive != tokenProvider1.tokenTimeToLive || !flag9) { return(false); } if (sharedAccessSignatureTokenProvider.encodedSharedAccessKey != null && tokenProvider1.encodedSharedAccessKey != null) { if ((int)sharedAccessSignatureTokenProvider.encodedSharedAccessKey.Length != (int)tokenProvider1.encodedSharedAccessKey.Length) { return(false); } if (!sharedAccessSignatureTokenProvider.encodedSharedAccessKey.SequenceEqual <byte>(tokenProvider1.encodedSharedAccessKey)) { return(false); } } } if (oAuthTokenProvider != null && oAuthTokenProvider1 != null && oAuthTokenProvider.IsWebTokenSupported != oAuthTokenProvider1.IsWebTokenSupported) { return(false); } if (windowsTokenProvider != null && windowsTokenProvider1 != null) { if (windowsTokenProvider.IsWebTokenSupported != windowsTokenProvider1.IsWebTokenSupported || windowsTokenProvider.stsUris.Count != windowsTokenProvider1.stsUris.Count) { return(false); } if (windowsTokenProvider.stsUris.Where <Uri>((Uri t, int i) => t != windowsTokenProvider1.stsUris[i]).Any <Uri>()) { return(false); } if (windowsTokenProvider.credential == null && windowsTokenProvider1.credential != null || windowsTokenProvider.credential != null && windowsTokenProvider1.credential == null) { return(false); } if (windowsTokenProvider.credential != null && windowsTokenProvider1.credential != null && (!windowsTokenProvider.credential.Domain.Equals(windowsTokenProvider1.credential.Domain, StringComparison.OrdinalIgnoreCase) || !windowsTokenProvider.credential.UserName.Equals(windowsTokenProvider1.credential.UserName, StringComparison.OrdinalIgnoreCase) || !windowsTokenProvider.credential.Password.Equals(windowsTokenProvider1.credential.Password))) { return(false); } } return(factory1.Address == factory2.Address); }