/// <summary>
        /// Creates a new instance of the <see cref="WorldGeocoder"/> class for the specified
        /// service configuration.
        /// </summary>
        /// <param name="serviceInfo">The instance of the geocoding service configuration
        /// specifying World geocoder service to create geocoder for.</param>
        /// <param name="exceptionHandler">Exception handler.</param>
        /// <returns>A new instance of the <see cref="WorldGeocoder"/> class.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="serviceInfo"/> is a null
        /// reference.</exception>
        public static GeocoderBase CreateWorldGeocoder(GeocodingServiceInfo serviceInfo,
            IServiceExceptionHandler exceptionHandler)
        {
            CodeContract.RequiresNotNull("serviceInfo", serviceInfo);

            // Create binding for the geocoder REST service.
            var webBinding = ServiceHelper.CreateWebHttpBinding("WorldGeocoder");
            var binding = new CustomBinding(webBinding);
            var messageEncodingElement = binding.Elements.Find<WebMessageEncodingBindingElement>();
            messageEncodingElement.ContentTypeMapper = new ArcGisWebContentTypeMapper();

            // Create endpoint for the geocoder REST service.
            var contract = ContractDescription.GetContract(typeof(IGeocodingService));
            var serviceAddress = new EndpointAddress(serviceInfo.RestUrl);
            var endpoint = new WebHttpEndpoint(contract, serviceAddress);
            endpoint.Binding = binding;

            // Replace default endpoint behavior with a customized one.
            endpoint.Behaviors.Remove<WebHttpBehavior>();
            endpoint.Behaviors.Add(new GeocodingServiceWebHttpBehavior());

            // Create the geocoder instance.
            var channelFactory = new WebChannelFactory<IGeocodingService>(endpoint);
            var client = new GeocodingServiceClient(channelFactory, serviceInfo, exceptionHandler);

            return new WorldGeocoder(serviceInfo, client);
        }
 private static ServiceEndpoint CreateEndpoint(Binding binding, EndpointAddress address, ContractDescription cd, Endpoint serviceInterface)
 {
     if (!serviceInterface.EndpointName.EqualsCaseInsensitive("rest") && !serviceInterface.EndpointName.EqualsCaseInsensitive("securerest"))
         return new ServiceEndpoint(cd, binding, address);
     var restEndpoint = new WebHttpEndpoint(cd, address)
                {
                    HelpEnabled = true,
                    DefaultOutgoingResponseFormat = WebMessageFormat.Json,
                    Binding = binding,
                    FaultExceptionEnabled = true,
                    AutomaticFormatSelectionEnabled = true
                    
                };
     restEndpoint.AutomaticFormatSelectionEnabled = true;
     restEndpoint.FaultExceptionEnabled = true;
     return restEndpoint;
 }
示例#3
0
		public void ReplaceBinding2 ()
		{
			var se = new WebHttpEndpoint (ContractDescription.GetContract (typeof (IMetadataExchange)), null);
			se.Binding = new NetTcpBinding ();
			se.WriteEncoding = Encoding.UTF8;
		}
示例#4
0
		public void ReplaceBinding1 ()
		{
			var se = new WebHttpEndpoint (ContractDescription.GetContract (typeof (IMetadataExchange)), null);
			se.Binding = new NetTcpBinding (); // this does not throw exception yet.
		}