Ejemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var client = new MyWcfServiceClient();

            countryLabel.Content = client.CountryByCode(isoField.Text);
            client.Close();
        }
Ejemplo n.º 2
0
        public NameSearch()
        {
            InitializeComponent();

            this.ViewModel = new NameSearchViewModel();
            this.DataContext = this.ViewModel;

            var service = new MyWcfServiceClient();

            var nameSearchObs = Observable.FromAsyncPattern<string, IEnumerable<string>>(service.BeginSelectNamesStartWith, service.EndSelectNamesStartWith);

            var nameTextBoxTextChanged = Observable.FromEventPattern<TextChangedEventArgs>(this.NameTextBox, "TextChanged");

            var textChangedObs =
                nameTextBoxTextChanged
                .ObserveOnDispatcher()
                .Select(x => ((TextBox)x.Sender).Text)
                .Throttle(TimeSpan.FromSeconds(3))
                .Where(x => x.Length >= 3)
                .Distinct();

            textChangedObs.ObserveOnDispatcher().Subscribe(x => this.ViewModel.PreviousSearches.Add(x));

            var searchResultObs =
                textChangedObs
                .Select(x => nameSearchObs(x))
                .Switch();

            searchResultObs.ObserveOnDispatcher().Subscribe(
                x => this.ViewModel.CurrentResults.ReplaceAll(x));
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("调用 WCF 服务开始!");

            using (MyWcfServiceClient service = new MyWcfServiceClient("BasicHttpBinding_IMyWcfService"))
            {

                Console.WriteLine("调用 service.GetData(100), 返回:" + service.GetData(100));

                CompositeType ct = new CompositeType()
                {
                    StringValue = "Test",
                    BoolValue = true
                };

                Console.WriteLine("调用前 ct: BoolValue={0}; StringValue={1}", ct.BoolValue, ct.StringValue);

                Console.WriteLine("调用 service.GetDataUsingDataContract(ct)");

                ct = service.GetDataUsingDataContract(ct);

                Console.WriteLine("调用后 ct: BoolValue={0}; StringValue={1}", ct.BoolValue, ct.StringValue);

            }

            Console.WriteLine("调用 WCF 服务结束!");
            Console.ReadLine();
        }
Ejemplo n.º 4
0
        // begin/end
        private void GetServerTimeButton3_Click(object sender, RoutedEventArgs e)
        {
            // update request time textblock
            this.RequestTimeTextBlock3.Text = DateTime.UtcNow.ToString(DateTimeFormat);

            var service = new MyWcfServiceClient();

            var asyncResult = service.BeginGetCurrentDateTimeUtc(this.GetCurrentDateTimeUtcAsyncCallback, service);
        }
        // GET: Default
        public ActionResult Index()
        {
            ServiceReference1.AddCalculatorServiceSoapClient obj = new AddCalculatorServiceSoapClient();
            int result = obj.Add(12, 15);

            ServiceReference2.MyWcfServiceClient obj2 = new MyWcfServiceClient();
            int result2 = obj2.MyCalculator(12, 15);

            return(Content(result.ToString() + "," + result2.ToString()));
        }
Ejemplo n.º 6
0
        // async/completed
        private void GetServerTimeButton2_Click(object sender, RoutedEventArgs e)
        {
            // update request time textblock
            this.RequestTimeTextBlock2.Text = DateTime.UtcNow.ToString(DateTimeFormat);

            var service = new MyWcfServiceClient();

            // wire up completed event
            service.GetCurrentDateTimeUtcCompleted += service_GetCurrentDateTimeUtcCompleted;

            // service call will not block
            service.GetCurrentDateTimeUtcAsync();
        }
Ejemplo n.º 7
0
        // Rx
        private void GetServerTimeButton4_Click(object sender, RoutedEventArgs e)
        {
            // update request time textblock
            this.RequestTimeTextBlock4.Text = DateTime.UtcNow.ToString(DateTimeFormat);

            var service = new MyWcfServiceClient();

            var obs = Observable.FromAsyncPattern<DateTime>(service.BeginGetCurrentDateTimeUtc, service.EndGetCurrentDateTimeUtc);

            // does not block  (note: needs ObserveOnDispatcher)
            obs().ObserveOnDispatcher().Subscribe(

            // OnNext
            x =>
            {
                // service call returned, update textblock
                this.ServerTimeTextBlock4.Text = x.ToString(DateTimeFormat);
            },

            // OnError
            ex =>
            {
                this.ServerTimeTextBlock4.Text = "Error Occurred";
            },

            // OnCompleted
            () =>
            {
                // the service call returned, the Observable Completed, update the response textblock
                this.ResponseTimeTextBlock4.Text = DateTime.UtcNow.ToString(DateTimeFormat);
            });
        }
Ejemplo n.º 8
0
        // block
        private void GetServerTimeButton_Click(object sender, RoutedEventArgs e)
        {
            // update request time textblock
            this.RequestTimeTextBlock.Text = DateTime.UtcNow.ToString(DateTimeFormat);

            // service call may error
            try
            {
                var service = new MyWcfServiceClient();

                // service call will block
                var currentDateTimeUtc = service.GetCurrentDateTimeUtc();

                // service call returned, update textblock
                this.ServerTimeTextBlock.Text = currentDateTimeUtc.ToString(DateTimeFormat);

                // update textblock that shows we have received the response
                this.ResponseTimeTextBlock.Text = DateTime.UtcNow.ToString(DateTimeFormat);
            }
            catch
            {
                this.ServerTimeTextBlock.Text = "Error Occurred";
            }
        }
Ejemplo n.º 9
0
        private void GetServerTimeButton6_Click(object sender, RoutedEventArgs e)
        {
            // update request time textblock
            this.RequestTimeTextBlock6.Text = DateTime.UtcNow.ToString(DateTimeFormat);

            var service = new MyWcfServiceClient();

            var obsTime = Observable.FromAsyncPattern<DateTime>(service.BeginGetCurrentDateTimeUtc, service.EndGetCurrentDateTimeUtc);
            var obsToString = Observable.FromAsyncPattern<DateTime, string>(service.BeginDateTimeToString, service.EndDateTimeToString);

            ////var chain = obsTime().SelectMany(x => obsToString(x));

            var chain =
                from dt in obsTime()
                from ts in obsToString(dt)
                select new { dt, ts };

            chain.ObserveOnDispatcher().Subscribe(

            // OnNext
            x =>
            {
                // service call returned, update textblock
                this.ServerTimeTextBlock6.Text = x.dt.ToString(DateTimeFormat);
            },

            // OnError
            ex =>
            {
                this.ServerTimeTextBlock6.Text = "Error Occurred";
            },

            // OnCompleted
            () =>
            {
                // the service call returned, the Observable Completed, update the response textblock
                this.ResponseTimeTextBlock6.Text = DateTime.UtcNow.ToString(DateTimeFormat);
            });
        }
Ejemplo n.º 10
0
        private void GetServerTimeButton5_Click(object sender, RoutedEventArgs e)
        {
            // update request time textblock
            this.RequestTimeTextBlock5.Text = DateTime.UtcNow.ToString(DateTimeFormat);

            var service = new MyWcfServiceClient();

            var obsTime = Observable.FromAsyncPattern<DateTime>(service.BeginGetCurrentDateTimeUtc, service.EndGetCurrentDateTimeUtc);
            var obsRand = Observable.FromAsyncPattern<double>(service.BeginGetRandomNumber, service.EndGetRandomNumber);

            var join =
                Observable
                .When(
                    obsTime().And(obsRand())
                    .Then((d, r) => new Tuple<DateTime, double>(d, r)));

            join.ObserveOnDispatcher().Subscribe(

            // OnNext
            x =>
            {
                // service call returned, update textblock
                this.ServerTimeTextBlock5.Text = x.Item1.ToString(DateTimeFormat);
            },

            // OnError
            ex =>
            {
                this.ServerTimeTextBlock5.Text = "Error Occurred";
            },

            // OnCompleted
            () =>
            {
                // the service call returned, the Observable Completed, update the response textblock
                this.ResponseTimeTextBlock5.Text = DateTime.UtcNow.ToString(DateTimeFormat);
            });
        }