public void RelayCompositeMessage()
        {
            const string responseXml = "<CalculatorResponse xmlns=\"urn:services.stateless.be:unit:calculator\">" +
                                       "<s0:Result xmlns:s0=\"urn:services.stateless.be:unit:calculator\">one</s0:Result>" +
                                       "<s0:Result xmlns:s0=\"urn:services.stateless.be:unit:calculator\">two</s0:Result>" +
                                       "</CalculatorResponse>";

            StubServiceHost.FindDefaultService <ICalculatorService>()
            .Setup(s => s.Add(It.IsAny <XmlCalculatorRequest>()))
            .Returns(new StringStream(responseXml));

            ICalculatorService client = null;

            try
            {
                client = SimpleServiceClient <CalculatorService, ICalculatorService> .Create();

                var calculatorResult = client.Add(new XmlCalculatorRequest(CALCULATOR_REQUEST_XML));
                Assert.AreEqual(responseXml, calculatorResult.RawXmlBody);
                client.Close();
            }
            catch (Exception)
            {
                if (client != null)
                {
                    client.Abort();
                }
                throw;
            }
        }
Exemplo n.º 2
0
        private void btnCheckValue_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                msg.AppendLine("Calling service @" + DateTime.Now);
                msg.AppendLine("call IncrementNumber " + client.IncrementNumber().ToString());
                msg.AppendLine("SessionID " + client.InnerChannel.SessionId);

                //lblMessage.Content = "Calling service @" + DateTime.Now;
                //lblMessage.Content += "\n1st call value " + client.IncrementNumber().ToString();
                //lblMessage.Content += "\n2nd call value " + client.IncrementNumber().ToString();
                //lblMessage.Content += "\n3rd call value " + client.IncrementNumber().ToString();
                //lblMessage.Content += "\n4th call value " + client.IncrementNumber().ToString();
                //lblMessage.Content += "\n\n\nSessionID " + client.InnerChannel.SessionId;
                //lblMessage.Content = msg.ToString();
                listBox.Items.Add(msg.ToString());
            }
            catch (CommunicationException)
            {
                if (client.InnerChannel.State == CommunicationState.Faulted)
                {
                    msg.AppendLine("\nSession timed out. Your existing session will be lost. A new session will be created!");
                    client = new SimpleServiceClient();
                }
            }
        }
        //really simple action that returns json data of products from northwind
        public JsonResult GetProducts()
        {
            try
            {
                var client = new SimpleServiceClient();
                var products = client.GetProductData();

                //maybe use value injector for this
                List<ProductVM> productVMs = new List<ProductVM>();
                foreach (var product in products)
                {
                    var productVM = new ProductVM();
                    productVM.ProductID = product.ProductID;
                    productVM.ProductName = product.ProductName;
                    productVM.UnitsInStock = product.UnitInStock;
                    productVM.Discontinued = product.Discontinued;
                    productVMs.Add(productVM);
                }
                return Json(productVMs, JsonRequestBehavior.AllowGet);
            }
            catch (Exception)
            {
                //error msg
                return Json("false");
                throw;
            }
        }
        public void RelaySyncMessage()
        {
            StubServiceHost.FindDefaultService <ICalculatorService>()
            .Setup(s => s.Add(It.IsAny <XmlCalculatorRequest>()))
            .Returns(new StringStream(string.Format(CALCULATOR_RESPONSE_XML, 3)));

            ICalculatorService client = null;

            try
            {
                client = SimpleServiceClient <CalculatorService, ICalculatorService> .Create();

                var calculatorResult = client.Add(new XmlCalculatorRequest(CALCULATOR_REQUEST_XML));
                Assert.AreEqual(string.Format(CALCULATOR_RESPONSE_XML, 3), calculatorResult.RawXmlBody);
                client.Close();
            }
            catch (Exception)
            {
                if (client != null)
                {
                    client.Abort();
                }
                throw;
            }
        }
        //really simple action that returns json data of products from northwind
        public JsonResult GetProducts()
        {
            try
            {
                var client   = new SimpleServiceClient();
                var products = client.GetProductData();

                //maybe use value injector for this
                List <ProductVM> productVMs = new List <ProductVM>();
                foreach (var product in products)
                {
                    var productVM = new ProductVM();
                    productVM.ProductID    = product.ProductID;
                    productVM.ProductName  = product.ProductName;
                    productVM.UnitsInStock = product.UnitInStock;
                    productVM.Discontinued = product.Discontinued;
                    productVMs.Add(productVM);
                }
                return(Json(productVMs, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                //error msg
                return(Json("false"));

                throw;
            }
        }
        static void Main(string[] args)
        {
            ServiceReference1.SimpleServiceClient proxy = new SimpleServiceClient();
            var x = proxy.DoWork(10);

            Console.ReadLine();
        }
Exemplo n.º 7
0
        private void buttonAuthentication_Click(object sender, EventArgs e)
        {
            InstanceContext     instanceContext = new InstanceContext(this);
            SimpleServiceClient client          = new SimpleServiceClient(instanceContext);

            MessageBox.Show(client.GetUserName());
        }
        public void RelayAsyncMessage()
        {
            StubServiceHost.FindDefaultService <ICalculatorService>()
            .Setup(s => s.BeginMultiply(It.IsAny <XmlCalculatorRequest>(), It.IsAny <AsyncCallback>(), It.IsAny <object>()))
            .Returns(new StringStream(string.Format(CALCULATOR_RESPONSE_XML, 2)));

            ICalculatorService client = null;

            try
            {
                client = SimpleServiceClient <CalculatorService, ICalculatorService> .Create();

                var calculatorResult = Task <XmlCalculatorResponse> .Factory
                                       .FromAsync(client.BeginMultiply, client.EndMultiply, new XmlCalculatorRequest(CALCULATOR_REQUEST_XML), null)
                                       .Result;

                Assert.AreEqual(string.Format(CALCULATOR_RESPONSE_XML, 2), calculatorResult.RawXmlBody);
                client.Close();
            }
            catch (Exception)
            {
                if (client != null)
                {
                    client.Abort();
                }
                throw;
            }
        }
Exemplo n.º 9
0
        private void buttonProcessReportReentrant_Click(object sender, EventArgs e)
        {
            InstanceContext     instanceContext = new InstanceContext(this);
            SimpleServiceClient client          = new SimpleServiceClient(instanceContext);

            client.ProgressReport();
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            ISimpleService srvc = new SimpleServiceClient();

              Console.WriteLine(srvc.GetData());
              Console.ReadLine();
        }
Exemplo n.º 11
0
        private void buttonSessionId_Click(object sender, EventArgs e)
        {
            InstanceContext     instanceContext = new InstanceContext(this);
            SimpleServiceClient client          = new SimpleServiceClient(instanceContext);

            //SimpleServiceClient client = new SimpleServiceClient();
            client.DisplaySessionId();
            MessageBox.Show($"Session ID = {client.InnerChannel.SessionId}");
        }
Exemplo n.º 12
0
        private void buttonDoWork_Click(object sender, EventArgs e)
        {
            InstanceContext     instanceContext = new InstanceContext(this);
            SimpleServiceClient client          = new SimpleServiceClient(instanceContext);

            for (int i = 1; i <= 100; i++)
            {
                Thread thread = new Thread(client.DoWork);
                thread.Start();
            }
        }
Exemplo n.º 13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Thread.Sleep(1500);

            ClientSection cs = HttpContext.Current.GetSection("system.serviceModel/client") as ClientSection;
            if (cs.Endpoints.Count > 0)
                endpointAddress.InnerText = cs.Endpoints[0].Address.AbsoluteUri;

            ISimpleService client = new SimpleServiceClient();
            client.PrintMessage("Calling from Web Client.");
        }
Exemplo n.º 14
0
        static void Main()
        {
            SimpleServiceClient client = new SimpleServiceClient();

            DateTime testDate = DateTime.Now;

            Console.WriteLine(client.GetDayOfWeekInBulgarian(testDate));
            // Use the 'client' variable to call operations on the service.

            // Always close the client.
            client.Close();
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            var client   = new SimpleServiceClient();
            var response = client.Authenticate(new AuthenticationRequest
            {
                Username = "******",
                Password = "******"
            });

            Console.WriteLine(response.Valid ? response.Message : "Error!");
            Console.ReadLine();
        }
Exemplo n.º 16
0
        public void RelaySyncInvalidMessageFails()
        {
            var client = SimpleServiceClient <CalculatorService, IValidatingCalculatorService> .Create();

            Assert.That(
                () => client.Add(new XlangCalculatorRequest(INVALID_CALCULATOR_REQUEST_XML)),
                Throws.TypeOf <FaultException <ExceptionDetail> >()
                .With.Property("Detail")
                .With.InnerException.InnerException.Message.Contains(
                    "The element 'Arguments' in namespace 'urn:services.stateless.be:unit:calculator' has invalid child element 'Operand' in namespace 'urn:services.stateless.be:unit:calculator'. "
                    + "List of possible elements expected: 'Term' in namespace 'urn:services.stateless.be:unit:calculator'"));
            client.Close();
        }
Exemplo n.º 17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Give time to ServiceHost to initialize.
            Thread.Sleep(1500);

            // Read configuation section and print wcf service host url to page.
            var wcfClientSection = HttpContext.Current.GetSection("system.serviceModel/client") as ClientSection;
            if (wcfClientSection.Endpoints.Count > 0)
                endpointAddress.InnerText = wcfClientSection.Endpoints[0].Address.AbsoluteUri;

            // Send message to wcf service host.
            ISimpleService client = new SimpleServiceClient();
            client.PrintMessage("Calling from Web Client.");
        }
        public void RelaySyncMessageTimesOut()
        {
            StubServiceHost.FindDefaultService <ICalculatorService>()
            .Setup(s => s.Subtract(It.IsAny <XmlCalculatorRequest>()))
            .Callback(() => Thread.Sleep(3000))
            .Returns(new StringStream(string.Format(CALCULATOR_RESPONSE_XML, 1)));

            var client = SimpleServiceClient <CalculatorService, ICalculatorService> .Create();

            Assert.That(
                () => client.Subtract(new XmlCalculatorRequest(CALCULATOR_REQUEST_XML)),
                Throws.TypeOf <FaultException <ExceptionDetail> >()
                .With.Message.Contains("The request channel timed out while waiting for a reply"));
            client.Close();
        }
Exemplo n.º 19
0
        public void RelayAsyncInvalidMessageFails()
        {
            var client = SimpleServiceClient <CalculatorService, IValidatingCalculatorService> .Create();

            Assert.That(
                () => Task <XlangCalculatorResponse> .Factory
                .FromAsync(client.BeginMultiply, client.EndMultiply, new XlangCalculatorRequest(INVALID_CALCULATOR_REQUEST_XML), null)
                .Result,
                Throws.TypeOf <AggregateException>()
                .With.InnerException.TypeOf <FaultException <ExceptionDetail> >()
                .With.InnerException.Property("Detail")
                .With.InnerException.InnerException.Message.Contains(
                    "The element 'Arguments' in namespace 'urn:services.stateless.be:unit:calculator' has invalid child element 'Operand' in namespace 'urn:services.stateless.be:unit:calculator'. "
                    + "List of possible elements expected: 'Term' in namespace 'urn:services.stateless.be:unit:calculator'"));
            client.Close();
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            var soapClient   = new SimpleServiceClient();
            var soapResponse = soapClient.GetData(4234);

            if (soapResponse != null)
            {
                Console.WriteLine(soapResponse);
            }

            var request = new AuthenticationRequest
            {
                Username = "******",
                Password = "******"
            };
            var soapResponse2 = soapClient.Authenticate(request);

            soapClient.Close();

            using (var restClient = new HttpClient
            {
                BaseAddress = new Uri("http://localhost:63852/SimpleService.svc/json/")
            })
            {
                var serilized    = JsonConvert.SerializeObject(request);
                var inputMessage = new HttpRequestMessage
                {
                    Content = new StringContent(serilized, Encoding.UTF8, "application/json")
                };
                inputMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var message = restClient.PutAsync("AuthReq", inputMessage.Content).Result;
                AuthorizationResponse restResponse = null;
                if (message.IsSuccessStatusCode)
                {
                    var inter = message.Content.ReadAsStringAsync();
                    restResponse = JsonConvert.DeserializeObject <AuthorizationResponse>(inter.Result);
                }

                if (restResponse != null)
                {
                    Console.WriteLine(restResponse.Message);
                }
            }

            Console.ReadKey();
        }
        public void RelayAsyncMessageTimesOut()
        {
            StubServiceHost.FindDefaultService <ICalculatorService>()
            .Setup(s => s.BeginDivide(It.IsAny <XmlCalculatorRequest>(), It.IsAny <AsyncCallback>(), It.IsAny <object>()))
            .Callback(() => Thread.Sleep(3000))
            .Returns(new StringStream(string.Format(CALCULATOR_RESPONSE_XML, 2)));

            var client = SimpleServiceClient <CalculatorService, ICalculatorService> .Create();

            Assert.That(
                () => Task <XmlCalculatorResponse> .Factory
                .FromAsync(client.BeginDivide, client.EndDivide, new XmlCalculatorRequest(CALCULATOR_REQUEST_XML), null)
                .Result,
                Throws.TypeOf <AggregateException>()
                .With.InnerException.TypeOf <FaultException <ExceptionDetail> >()
                .With.InnerException.Message.Contains("has exceeded the allotted timeout"));
            client.Close();
        }
Exemplo n.º 22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Give time to ServiceHost to initialize.
            Thread.Sleep(1500);

            // Read configuation section and print wcf service host url to page.
            var wcfClientSection = HttpContext.Current.GetSection("system.serviceModel/client") as ClientSection;

            if (wcfClientSection.Endpoints.Count > 0)
            {
                endpointAddress.InnerText = wcfClientSection.Endpoints[0].Address.AbsoluteUri;
            }


            // Send message to wcf service host.
            ISimpleService client = new SimpleServiceClient();

            client.PrintMessage("Calling from Web Client.");
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            // Vytvorenie instancie proxy triedy, pomocou ktorej mozeme volat vzdialene metody
            var client = new SimpleServiceClient();

            // Zavolame vzdialenu metodu GetData - sluzba vrati retazec
            var resultString = client.GetData(123);

            Console.WriteLine(resultString);

            var compositeType = new CompositeType {
                StringValue = "Volam WCF sluzbu", BoolValue = true
            };
            var resultCompositeType = client.GetDataUsingDataContract(compositeType);

            Console.WriteLine(resultCompositeType.StringValue);

            Console.ReadLine();

            client.Close();
        }
Exemplo n.º 24
0
        private void button1_Click(object sender, EventArgs e)
        {
            SimpleServiceClient loclient = new SimpleServiceClient();
            int num1 = Convert.ToInt32(txtnum1.Text);
            int num2 = Convert.ToInt32(txtnum2.Text);

            if (comboBox1.Text == "ADD")
            {
                textBox1.Text = (loclient.Add(num1, num2)).ToString();
            }
            else if (comboBox1.Text == "SUBSTRACT")
            {
                textBox1.Text = loclient.Substract(num1, num2).ToString();
            }
            else if (comboBox1.Text == "MULTIPLY")
            {
                textBox1.Text = loclient.Multiply(num1, num2).ToString();
            }
            else if (comboBox1.Text == "DIVIDE")
            {
                textBox1.Text = loclient.Divide(num1, num2).ToString();
            }
        }
Exemplo n.º 25
0
        public static void Main(string[] args)
        {
            var simpleServiceClient       = new SimpleServiceClient();
            var simpleServiceCustomClient = new SimpleServiceCustomProxy(new BasicHttpBinding(), new System.ServiceModel.EndpointAddress(@"http://localhost:8123/SimpleService/"));
            var dulplexServiceClient      = new DulplexServiceClient(new System.ServiceModel.InstanceContext(new DulplexServiceCallback()));
            var dulplexServiceClient2     = new DulplexServiceClient(new System.ServiceModel.InstanceContext(new DulplexServiceCallback()));

            try
            {
                Console.WriteLine("Client - Start.");
                Console.WriteLine(simpleServiceClient.GetData(5));
                Console.WriteLine(simpleServiceCustomClient.GetData(2));
                var obj = new Contracts.CompositeType();
                obj.BoolValue   = true;
                obj.StringValue = "hello";
                var obj1 = simpleServiceCustomClient.GetDataUsingDataContract(obj);
                var obj2 = simpleServiceClient.GetDataUsingDataContract(obj);
                simpleServiceClient.Close();

                dulplexServiceClient.Subscribe();
                dulplexServiceClient2.Subscribe();
                dulplexServiceClient2.Subscribe();
                dulplexServiceClient2.UnSubscribe();
                dulplexServiceClient2.UnSubscribe();
                dulplexServiceClient2.UnSubscribe();
                dulplexServiceClient2.Close();
                dulplexServiceClient.Add(7, 8);
                //dulplexServiceClient.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                simpleServiceClient.Abort();
                dulplexServiceClient.Abort();
            }
            Console.Read();
        }
Exemplo n.º 26
0
        public void PerformSyncSucceeds()
        {
            StubServiceHost.FindDefaultService <IPerformService>()
            .Setup(s => s.Perform(It.IsAny <XlangCalculatorRequest>()));

            IPerformService client = null;

            try
            {
                var request = new XlangCalculatorRequest(CALCULATOR_REQUEST_XML);
                client = SimpleServiceClient <CalculatorService, IPerformService> .Create();

                client.Perform(request);
                client.Close();
            }
            catch (Exception)
            {
                if (client != null)
                {
                    client.Abort();
                }
                throw;
            }
        }
Exemplo n.º 27
0
        private void buttonServiceBehavior_Click(object sender, EventArgs e)
        {
            InstanceContext     instanceContext = new InstanceContext(this);
            SimpleServiceClient client          = new SimpleServiceClient(instanceContext);

            //SimpleServiceClient client = new SimpleServiceClient();
            MessageBox.Show($"Number after first call = {client.IncrementNumber()}");
            MessageBox.Show($"Number after second call = {client.IncrementNumber()}");
            MessageBox.Show($"Number after third call = {client.IncrementNumber()}");

            //// Handling session timeout exception
            //try
            //{
            //    MessageBox.Show($"Number = {client.IncrementNumber()}");
            //}
            //catch(CommunicationException)
            //{
            //    if (client.State == CommunicationState.Faulted)
            //    {
            //        MessageBox.Show($"Session timed out and existing session is lost. A new session will now be created.");
            //        client = new SimpleServiceClient();
            //    }
            //}
        }
Exemplo n.º 28
0
 public MainWindow()
 {
     InitializeComponent();
     client = new SimpleServiceClient();
     listBox.Items.Clear();
 }
Exemplo n.º 29
0
        public MFTestResults Start()
        {
            MFTestResults testResult = MFTestResults.Pass;

            try
            {
                //System.Ext.Console.Verbose = true;
                // Also start a local client on this device

                ProtocolVersion ver = new ProtocolVersion10();

                WS2007HttpBinding binding = new WS2007HttpBinding(new HttpTransportBindingConfig("urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51", 8084));

                Device.Initialize(binding, ver);

                // Set device information
                //Device.EndpointAddress = "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51";
                Device.ThisModel.Manufacturer    = "Microsoft Corporation";
                Device.ThisModel.ManufacturerUrl = "http://www.microsoft.com/";
                Device.ThisModel.ModelName       = "SimpleService Test Device";
                Device.ThisModel.ModelNumber     = "1.0";
                Device.ThisModel.ModelUrl        = "http://www.microsoft.com/";
                Device.ThisModel.PresentationUrl = "http://www.microsoft.com/";

                Device.ThisDevice.FriendlyName    = "SimpleService";
                Device.ThisDevice.FirmwareVersion = "alpha";
                Device.ThisDevice.SerialNumber    = "12345678";

                // Add a Host service type
                Device.Host = new SimpleDeviceHost();

                // Add DPWS hosted services to the device
                Device.HostedServices.Add(new SimpleService());
                Device.HostedServices.Add(new EventingService());
                Device.HostedServices.Add(new AttachmentService());

                Log.Comment("Start the Client");
                client = new SimpleServiceClient();
                client.IgnoreRequestFromThisIP = false;

                Thread.Sleep(500);

                // Set to true to ignore the local client's requests
                Device.IgnoreLocalClientRequest = false;

                // Start the device stack
                Log.Comment("Start the Device");
                ServerBindingContext ctx = new ServerBindingContext(ver);
                Device.Start(ctx);
                int timeOut = 600000;
                //  The Client should be done intergoating the service within 10 minutes
                if (!client.arHello.WaitOne(timeOut, false))
                {
                    Log.Comment("Client not done interogating the service for '" + timeOut + "' milliseconds");
                }
            }
            catch (Exception e)
            {
                Log.Comment("Unexpected Exception e: " + e.ToString());
            }
            finally
            {
                try
                {
                    Log.Comment("Stopping the service");
                    Device.Stop();
                }
                catch (Exception ex)
                {
                    Log.Comment("Caught : " + ex.Message);
                }
                Log.Comment("Waiting and verifying client received messages");

                //  Sleep for 15 seconds to let the client receive the bye events.
                client.arBye.WaitOne(15000, false);

                if (client != null)
                {
                    if (!client.m_receivedHelloEvent)
                    {
                        Log.Comment("Did not get HelloEvent.");
                        testResult = MFTestResults.Fail;
                    }
                    if (!client.m_getMex)
                    {
                        Log.Comment("Did not get GetMex.");
                        testResult = MFTestResults.Fail;
                    }
                    if (!client.m_twoWay)
                    {
                        Log.Comment("Did not get TwoWay.");
                        testResult = MFTestResults.Fail;
                    }
                    if (!client.m_receivedByeEvent)
                    {
                        Log.Comment("Did not get ByeEvent.");
                        testResult = MFTestResults.Fail;
                    }

                    client.Dispose();
                }
            }
            return(testResult);
        }
 static void Main(string[] args)
 {
     ServiceReference1.SimpleServiceClient proxy = new SimpleServiceClient();
     var x = proxy.DoWork(10);
     Console.ReadLine();
 }