Exemplo n.º 1
0
        private static ChannelFactory <T> CreateServiceBusClientChannelFactory <T>(string serviceNamespace, string servicePath, string issuerName, string issuerSecret, Binding binding)
        {
            Guard.ArgumentNotNullOrEmptyString(serviceNamespace, "serviceNamespace");
            Guard.ArgumentNotNullOrEmptyString(servicePath, "servicePath");
            Guard.ArgumentNotNullOrEmptyString(issuerName, "issuerName");
            Guard.ArgumentNotNullOrEmptyString(issuerSecret, "issuerSecret");
            Guard.ArgumentNotNull(binding, "binding");

            var callToken = TraceManager.DebugComponent.TraceIn(serviceNamespace, servicePath, binding.Name);

            var address = ServiceBusEnvironment.CreateServiceUri(WellKnownProtocolScheme.ServiceBus, serviceNamespace, servicePath);

            var credentialsBehaviour = new TransportClientEndpointBehavior();

            credentialsBehaviour.CredentialType = TransportClientCredentialType.SharedSecret;
            credentialsBehaviour.Credentials.SharedSecret.IssuerName   = issuerName;
            credentialsBehaviour.Credentials.SharedSecret.IssuerSecret = issuerSecret;

            var endpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(T)), binding, new EndpointAddress(address));

            endpoint.Behaviors.Add(credentialsBehaviour);

            // Apply default endpoint configuration.
            ServiceEndpointConfiguration.ConfigureDefaults(endpoint);

            ChannelFactory <T> clientChannelFactory = new ChannelFactory <T>(endpoint);

            TraceManager.DebugComponent.TraceOut(callToken, endpoint.Address.Uri);

            return(clientChannelFactory);
        }
Exemplo n.º 2
0
        private static ServiceHost CreateServiceBusHost(string serviceNamespace, string servicePath, string issuerName, string issuerSecret, Binding binding, Type serviceType)
        {
            Guard.ArgumentNotNullOrEmptyString(serviceNamespace, "serviceNamespace");
            Guard.ArgumentNotNullOrEmptyString(servicePath, "servicePath");
            Guard.ArgumentNotNullOrEmptyString(issuerName, "issuerName");
            Guard.ArgumentNotNullOrEmptyString(issuerSecret, "issuerSecret");
            Guard.ArgumentNotNull(binding, "binding");

            var callToken = TraceManager.DebugComponent.TraceIn(serviceNamespace, servicePath, binding.Name);

            var address = ServiceBusEnvironment.CreateServiceUri(WellKnownProtocolScheme.ServiceBus, serviceNamespace, servicePath);

            var credentialsBehaviour = new TransportClientEndpointBehavior();

            credentialsBehaviour.CredentialType = TransportClientCredentialType.SharedSecret;
            credentialsBehaviour.Credentials.SharedSecret.IssuerName   = issuerName;
            credentialsBehaviour.Credentials.SharedSecret.IssuerSecret = issuerSecret;

            var endpoint = new ServiceEndpoint(ContractDescription.GetContract(GetServiceContract(serviceType)), binding, new EndpointAddress(address));

            endpoint.Behaviors.Add(credentialsBehaviour);

            // Apply default endpoint configuration.
            ServiceEndpointConfiguration.ConfigureDefaults(endpoint);

            ServiceBehaviorAttribute serviceBehaviorAttr = FrameworkUtility.GetDeclarativeAttribute <ServiceBehaviorAttribute>(serviceType);
            ServiceHost host = null;

            if (serviceBehaviorAttr != null && serviceBehaviorAttr.InstanceContextMode == InstanceContextMode.Single)
            {
                host = new ServiceHost(Activator.CreateInstance(serviceType));
            }
            else
            {
                host = new ServiceHost(serviceType);
            }

            host.Description.Endpoints.Add(endpoint);
#if DEBUG
            var debugBehavior = new ServiceDebugBehavior();
            debugBehavior.IncludeExceptionDetailInFaults = true;

            host.Description.Behaviors.Remove <ServiceDebugBehavior>();
            host.Description.Behaviors.Add(debugBehavior);
#endif
            TraceManager.DebugComponent.TraceOut(callToken, endpoint.Address.Uri);

            return(host);
        }