Example #1
0
        public async Task <StockQuote> GetQuoteForSymbol(string symbols)
        {
            var request = new StockQuoteRequest();
            var message = await request.RequestStockQuotes(symbols);

            var quoteList = message.Quotes;
            var newQuote  = quoteList[0];

            return(newQuote);
        }
Example #2
0
        TestConsole()
        {
            CustomBinding binding = new CustomBinding();
            MtomMessageEncodingBindingElement mtomBindingElement = new MtomMessageEncodingBindingElement();

            mtomBindingElement.MessageVersion = MessageVersion.Soap11WSAddressingAugust2004;
            binding.Elements.Add(mtomBindingElement);
            binding.Elements.Add(new WseTcpTransportBindingElement());

            // WSE sample uses a logical endpoint. So we need to set the physical via separately.
            EndpointAddress address = new EndpointAddress("soap://stockservice.contoso.com/wse/samples/2003/06/TcpSyncStockService");

            // INSERT your HOSTNAME here:
            string hostname = "localhost";
            Uri    via      = new Uri(string.Format("soap.tcp://{0}/StockService", hostname));
            StockServicePortTypeClient client = new StockServicePortTypeClient(binding, address);

            client.Endpoint.Behaviors.Add(new ClientViaBehavior(via));
            Console.WriteLine("Calling {0}", client.Endpoint.Address.Uri.AbsoluteUri);

            StockQuoteRequest quoteRequest = new StockQuoteRequest();

            quoteRequest.symbols = new ArrayOfString();
            quoteRequest.symbols.Add("FABRIKAM");
            quoteRequest.symbols.Add("CONTOSO");
            StockQuotes stocks = client.GetStockQuotes(quoteRequest);

            foreach (StockQuote quote in stocks)
            {
                Console.WriteLine("");
                Console.WriteLine("Symbol: " + quote.Symbol);
                Console.WriteLine("\tName: " + quote.Name);
                Console.WriteLine("\tLast Price: " + quote.Last);
            }
            Console.WriteLine("Press enter.");
            Console.ReadLine();

            binding             = new CustomBinding(new WseTcpTransportBindingElement());
            this.uri            = new Uri("wse.tcp://localhost:9000/a/b/");
            this.channelFactory = binding.BuildChannelFactory <IDuplexSessionChannel>();
            this.listener       = binding.BuildChannelListener <IDuplexSessionChannel>(this.uri);
        }