Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("########################################");
            Console.WriteLine("# WCF Simple Client 1.0 by HarryGG");
            Console.WriteLine("########################################" + Environment.NewLine);

            string selection = "Type: 1 to add comment, 2 to view comments, 3 to exit";

            Console.WriteLine(selection);
            Console.Write(">");
            string action  = Console.ReadLine();
            string comment = null;
            string name    = null;
            //EvalServiceClient WSHttpBinding_client = new EvalServiceClient("WSHttpBinding_IEvalService");
            EvalServiceClient WSHttpBinding_client = new EvalServiceClient();

            try
            {
                while (action != "3" && action != "exit")
                {
                    switch (action)
                    {
                    case "1":
                        Console.WriteLine("Write comment and hit <Enter> to submit:");
                        comment = Console.ReadLine();
                        Console.WriteLine("Write your name and hit <Enter> to submit:");
                        name = Console.ReadLine();

                        Eval eval = new Eval();
                        eval.Comments      = comment;
                        eval.Submitter     = name;
                        eval.TimeSubmitted = DateTime.Now;

                        System.ServiceModel.Configuration.ClientSection clientSection =
                            (System.ServiceModel.Configuration.ClientSection)ConfigurationManager.GetSection("system.serviceModel/client");
                        System.ServiceModel.Configuration.ChannelEndpointElement endpoint = clientSection.Endpoints[0];

                        //string endpointStr = endpoint.Address.ToString();

                        Console.WriteLine("Submitting comment to endpoint ");    // + endpointStr);
                        WSHttpBinding_client.SubmitEval(eval);
                        Console.WriteLine("Comment submitted!" + Environment.NewLine);

                        Console.WriteLine(selection);
                        Console.Write(">");
                        action = Console.ReadLine();
                        break;

                    case "2":
                        Console.WriteLine("Getting list of submitted comments...");
                        Eval[] evals = WSHttpBinding_client.GetEvals();

                        int i = 0;
                        if (evals.Length > 0)
                        {
                            Console.WriteLine(evals.Length + " comments retrieved successfully:");
                            Console.WriteLine(Environment.NewLine);
                            foreach (Eval ev in evals)
                            {
                                Console.WriteLine(++i + ": " + ev.Comments + " from user " + ev.Submitter);
                            }
                        }
                        else
                        {
                            Console.WriteLine(Environment.NewLine);
                            Console.WriteLine("No comments found! I suggest you first add some comments!");
                        }
                        Console.WriteLine(Environment.NewLine);

                        Console.WriteLine(selection);
                        Console.Write(">");
                        action = Console.ReadLine();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.WriteLine("*********************************************************");
            //Console.WriteLine(selection);
            //Console.Write(">");
            //action = Console.ReadLine();
        }
Exemple #2
0
        protected virtual void ApplyConfiguration(string endpointConfig)
        {
            if (endpointConfig == null)
            {
                return;
            }
                        #if NET_2_1 || XAMMAC_4_5
            try {
                // It should automatically use XmlXapResolver
                var cfg = new SilverlightClientConfigLoader().Load(XmlReader.Create("ServiceReferences.ClientConfig"));

                SilverlightClientConfigLoader.ServiceEndpointConfiguration se = null;
                if (endpointConfig == "*")
                {
                    se = cfg.GetServiceEndpointConfiguration(Endpoint.Contract.Name);
                }
                if (se == null)
                {
                    se = cfg.GetServiceEndpointConfiguration(endpointConfig);
                }

                if (se.Binding != null && Endpoint.Binding == null)
                {
                    Endpoint.Binding = se.Binding;
                }
                else                 // ignore it
                {
                    Console.WriteLine("WARNING: Configured binding not found in configuration {0}", endpointConfig);
                }
                if (se.Address != null && Endpoint.Address == null)
                {
                    Endpoint.Address = se.Address;
                }
                else                 // ignore it
                {
                    Console.WriteLine("WARNING: Configured endpoint address not found in configuration {0}", endpointConfig);
                }
            } catch (Exception) {
                // ignore it.
                Console.WriteLine("WARNING: failed to load endpoint configuration for {0}", endpointConfig);
            }
#else
            string contractName = Endpoint.Contract.ConfigurationName;
            var    client       = Colosoft.ServiceModel.Configuration.ConfigUtil.ClientSection;
            System.ServiceModel.Configuration.ChannelEndpointElement endpoint = null;
            foreach (System.ServiceModel.Configuration.ChannelEndpointElement el in client.Endpoints)
            {
                if (el.Contract == contractName && (endpointConfig == el.Name || endpointConfig == "*"))
                {
                    if (endpoint != null)
                    {
                        throw new InvalidOperationException(String.Format("More then one endpoint matching contract {0} was found.", contractName));
                    }
                    endpoint = el;
                }
            }
            if (endpoint == null)
            {
                throw new InvalidOperationException(String.Format("Client endpoint configuration '{0}' was not found in {1} endpoints.", endpointConfig, client.Endpoints.Count));
            }
            var binding      = String.IsNullOrEmpty(endpoint.Binding) ? null : Colosoft.ServiceModel.Configuration.ConfigUtil.CreateBinding(endpoint.Binding, endpoint.BindingConfiguration);
            var contractType = Colosoft.ServiceModel.Configuration.ConfigUtil.GetTypeFromConfigString(endpoint.Contract, Colosoft.ServiceModel.Configuration.NamedConfigCategory.Contract);
            if (contractType == null)
            {
                throw new ArgumentException(String.Format("Contract '{0}' was not found", endpoint.Contract));
            }
            var contract = String.IsNullOrEmpty(endpoint.Contract) ? Endpoint.Contract : System.ServiceModel.Description.ContractDescription.GetContract(contractType);
            if (!String.IsNullOrEmpty(endpoint.Kind))
            {
                var se = Configuration.ConfigUtil.ConfigureStandardEndpoint(contract, endpoint);
                if (se.Binding == null)
                {
                    se.Binding = binding;
                }
                if (se.Address == null && se.Binding != null)
                {
                    se.Address = new EndpointAddress(endpoint.Address);
                }
                if (se.Binding == null && se.Address != null)
                {
                    se.Binding = Configuration.ConfigUtil.GetBindingByProtocolMapping(se.Address.Uri);
                }
                service_endpoint = se;
            }
            else
            {
                if (binding == null && endpoint.Address != null)
                {
                    Endpoint.Binding = Configuration.ConfigUtil.GetBindingByProtocolMapping(endpoint.Address);
                }
            }
            if (Endpoint.Binding == null)
            {
                Endpoint.Binding = Configuration.ConfigUtil.CreateBinding(endpoint.Binding, endpoint.BindingConfiguration);
            }
            if (Endpoint.Address == null)
            {
                Endpoint.Address = new EndpointAddress(endpoint.Address);
            }
            if (endpoint.BehaviorConfiguration != "")
            {
                ApplyBehavior(endpoint.BehaviorConfiguration);
            }
                        #endif
        }
        public System.CodeDom.CodeTypeReference GenerateServiceEndpoint(ServiceEndpoint endpoint, out System.ServiceModel.Configuration.ChannelEndpointElement channelElement)
        {
            Contract.Ensures(Contract.Result <System.CodeDom.CodeTypeReference>() != null);

            channelElement = default(System.ServiceModel.Configuration.ChannelEndpointElement);

            return(default(System.CodeDom.CodeTypeReference));
        }