Exemplo n.º 1
0
        protected override ChannelCreator GetChannel(RestClientModel clientModel, Type contract, Binding binding, string address,
                                                     IChannelBuilderScope scope)
        {
            var remoteAddress = new Uri(address, UriKind.Absolute);

            if (binding == null)
            {
                return(CreateChannelCreator(contract, clientModel, scope, remoteAddress));
            }

            return(CreateChannelCreator(contract, clientModel, scope, binding, remoteAddress));
        }
Exemplo n.º 2
0
        internal object DiscoverChannel(DiscoveredEndpointModel model, IChannelBuilderScope scope)
        {
            var discovered = PerformEndpointSearch(scope.Contract, model);

            if (discovered == null || discovered.Endpoints.Count == 0)
            {
                throw new EndpointNotFoundException(string.Format(
                                                        "Unable to discover the endpoint for contract {0}.  " +
                                                        "Either no service exists or it does not support discovery.",
                                                        scope.Contract.FullName));
            }

            var binding          = model.Binding;
            var endpointMetadata = discovered.Endpoints[0];

            if (discovered.Endpoints.Count > 1 && model.EndpointPreference != null)
            {
                endpointMetadata = model.EndpointPreference(discovered.Endpoints);
                if (endpointMetadata == null)
                {
                    throw new EndpointNotFoundException(string.Format(
                                                            "More than one endpoint was discovered for contract {0}.  " +
                                                            "However, an endpoint was not selected.  This is most likely " +
                                                            "a bug with the user-defined endpoint preference.",
                                                            scope.Contract.FullName));
                }
            }

            if (binding == null && model.DeriveBinding == false)
            {
                binding = GetBindingFromMetadata(endpointMetadata);
            }

            var address = endpointMetadata.Address;

            if (model.Identity != null)
            {
                address = new EndpointAddress(address.Uri, model.Identity, address.Headers);
            }

            binding = GetEffectiveBinding(binding, address.Uri);

            var channel = scope.GetChannel(scope.Contract, binding, address)();

            if (channel is IContextChannel)
            {
                var metadata = new DiscoveredEndpointMetadata(endpointMetadata);
                ((IContextChannel)channel).Extensions.Add(metadata);
            }

            return(channel);
        }
Exemplo n.º 3
0
		internal object DiscoverChannel(DiscoveredEndpointModel model, IChannelBuilderScope scope)
		{
			var discovered = PerformEndpointSearch(scope.Contract, model);

			if (discovered == null || discovered.Endpoints.Count == 0)
			{
				throw new EndpointNotFoundException(string.Format(
					"Unable to discover the endpoint for contract {0}.  " +
					"Either no service exists or it does not support discovery.",
					scope.Contract.FullName));
			}

			var binding = model.Binding;
			var endpointMetadata = discovered.Endpoints[0];
			if (discovered.Endpoints.Count > 1 && model.EndpointPreference != null)
			{
				endpointMetadata = model.EndpointPreference(discovered.Endpoints);
				if (endpointMetadata == null)
				{
					throw new EndpointNotFoundException(string.Format(
						"More than one endpoint was discovered for contract {0}.  " +
						"However, an endpoint was not selected.  This is most likely " +
						"a bug with the user-defined endpoint preference.",
						scope.Contract.FullName));
				}
			}

			if (binding == null && model.DeriveBinding == false)
			{
				binding = GetBindingFromMetadata(endpointMetadata);
			}

			var address = endpointMetadata.Address;
			if (model.Identity != null)
			{
				address = new EndpointAddress(address.Uri, model.Identity, address.Headers);
			}

			binding = GetEffectiveBinding(binding, address.Uri);

			var channel = scope.GetChannel(scope.Contract, binding, address)();

			if (channel is IContextChannel)
			{
				var metadata = new DiscoveredEndpointMetadata(endpointMetadata);
				((IContextChannel)channel).Extensions.Add(metadata);
			}

			return channel;
		}
Exemplo n.º 4
0
        protected override ChannelCreator CreateChannelCreator(Type contract, RestClientModel clientModel, IChannelBuilderScope scope,
                                                               params object[] channelFactoryArgs)
        {
            var type           = typeof(WebChannelFactory <>).MakeGenericType(new[] { contract });
            var channelFactory = ChannelFactoryBuilder.CreateChannelFactory(type, clientModel, channelFactoryArgs);

            scope.ConfigureChannelFactory(channelFactory);

            var methodInfo = type.GetMethod("CreateChannel", Type.EmptyTypes);

            return((ChannelCreator)Delegate.CreateDelegate(typeof(ChannelCreator), channelFactory, methodInfo));
        }
Exemplo n.º 5
0
 protected override ChannelCreator GetChannel(RestClientModel clientModel, Type contract, Binding binding, EndpointAddress address,
                                              IChannelBuilderScope scope)
 {
     return(GetChannel(clientModel, contract, binding, address.Uri.AbsoluteUri, scope));
 }
Exemplo n.º 6
0
 protected virtual ChannelCreator GetChannel(M clientModel, Type contract, Binding binding, EndpointAddress address, IChannelBuilderScope scope)
 {
     return(CreateChannelCreator(contract, clientModel, scope, binding, address));
 }
Exemplo n.º 7
0
 protected virtual ChannelCreator GetChannel(M clientModel, Type contract, string configurationName, IChannelBuilderScope scope)
 {
     return(CreateChannelCreator(contract, clientModel, scope, configurationName));
 }
Exemplo n.º 8
0
 protected virtual ChannelCreator GetChannel(M clientModel, Type contract, ServiceEndpoint endpoint, IChannelBuilderScope scope)
 {
     return(CreateChannelCreator(contract, clientModel, scope, endpoint));
 }
Exemplo n.º 9
0
 protected override ChannelCreator GetChannel(DuplexClientModel clientModel, Type contract, Binding binding, EndpointAddress address,
                                              IChannelBuilderScope scope)
 {
     return(CreateChannelCreator(contract, clientModel, scope, clientModel.CallbackContext, binding, address));
 }
Exemplo n.º 10
0
 protected override ChannelCreator GetChannel(DuplexClientModel clientModel, Type contract, string configurationName,
                                              IChannelBuilderScope scope)
 {
     return(CreateChannelCreator(contract, clientModel, scope, clientModel.CallbackContext, configurationName));
 }
Exemplo n.º 11
0
 protected override ChannelCreator GetChannel(DuplexClientModel clientModel, Type contract, ServiceEndpoint endpoint,
                                              IChannelBuilderScope scope)
 {
     return(CreateChannelCreator(contract, clientModel, scope, clientModel.CallbackContext, endpoint));
 }