Пример #1
0
        public virtual TwoWayResponse TwoWayRequest(TwoWayRequest req)
        {
            // Create request header
            String action;

            action = "http://schemas.example.org/SimpleService/TwoWayRequest";
            WsWsaHeader header;

            header = new WsWsaHeader(action, null, ServiceEndpoint, null, EndpointAddress, null);

            // Create request serializer
            TwoWayRequestDataContractSerializer reqDcs;

            reqDcs = new TwoWayRequestDataContractSerializer("TwoWayRequest", "http://schemas.example.org/SimpleService");

            // Build soap request message
            byte[] soapBuffer = SoapMessageBuilder.BuildSoapMessage(header, reqDcs, req);

            // Send service request
            DpwsHttpClient httpClient;

            httpClient = new DpwsHttpClient();
            DpwsSoapResponse response;

            response = httpClient.SendRequest(soapBuffer, ServiceEndpoint, false, false);

            // Process response
            TwoWayResponseDataContractSerializer respDcs;

            respDcs = new TwoWayResponseDataContractSerializer("TwoWayResponse", "http://schemas.example.org/SimpleService");
            TwoWayResponse resp;

            resp = ((TwoWayResponse)(respDcs.ReadObject(response.Reader)));
            return(resp);
        }
        public virtual TwoWayResponse TwoWay(TwoWayRequest req)
        {

            // Create request header
            String action;
            action = "http://schemas.example.org/SimpleService/TwoWay";
            WsWsaHeader header;
            header = new WsWsaHeader(action, null, EndpointAddress, m_version.AnonymousUri, null, null);
            WsMessage request = new WsMessage(header, req, WsPrefix.None);

            // Create request serializer
            TwoWayRequestDataContractSerializer reqDcs;
            reqDcs = new TwoWayRequestDataContractSerializer("TwoWayRequest", "http://schemas.example.org/SimpleService");
            request.Serializer = reqDcs;
            request.Method = "TwoWay";


            // Send service request
            m_requestChannel.Open();
            WsMessage response = m_requestChannel.Request(request);
            m_requestChannel.Close();

            // Process response
            TwoWayResponseDataContractSerializer respDcs;
            respDcs = new TwoWayResponseDataContractSerializer("TwoWayResponse", "http://schemas.example.org/SimpleService");
            TwoWayResponse resp;
            resp = ((TwoWayResponse)(respDcs.ReadObject(response.Reader)));
            return resp;
        }
        public virtual TwoWayResponse TwoWay(TwoWayRequest req)
        {
            // Create request header
            String action;

            action = "http://schemas.example.org/SimpleService/TwoWay";
            WsWsaHeader header;

            header = new WsWsaHeader(action, null, EndpointAddress, m_version.AnonymousUri, null, null);
            WsMessage request = new WsMessage(header, req, WsPrefix.None);

            // Create request serializer
            TwoWayRequestDataContractSerializer reqDcs;

            reqDcs             = new TwoWayRequestDataContractSerializer("TwoWayRequest", "http://schemas.example.org/SimpleService");
            request.Serializer = reqDcs;
            request.Method     = "TwoWay";


            // Send service request
            m_requestChannel.Open();
            WsMessage response = m_requestChannel.Request(request);

            m_requestChannel.Close();

            // Process response
            TwoWayResponseDataContractSerializer respDcs;

            respDcs = new TwoWayResponseDataContractSerializer("TwoWayResponse", "http://schemas.example.org/SimpleService");
            TwoWayResponse resp;

            resp = ((TwoWayResponse)(respDcs.ReadObject(response.Reader)));
            return(resp);
        }
Пример #4
0
        public override object ReadObject(XmlReader reader)
        {
            TwoWayRequest TwoWayRequestField = null;

            if (IsParentStartElement(reader, false, true))
            {
                TwoWayRequestField         = new TwoWayRequest();
                TwoWayRequestField.AnyAttr = ReadAnyAttribute(reader);
                reader.Read();
                if (IsChildStartElement(reader, "X", true, true))
                {
                    reader.Read();
                    TwoWayRequestField.X = XmlConvert.ToInt32(reader.ReadString());
                    reader.ReadEndElement();
                }
                if (IsChildStartElement(reader, "Y", true, true))
                {
                    reader.Read();
                    TwoWayRequestField.Y = XmlConvert.ToInt32(reader.ReadString());
                    reader.ReadEndElement();
                }
                TwoWayRequestField.Any = ReadAnyElement(reader, false);
                reader.ReadEndElement();
            }
            return(TwoWayRequestField);
        }
 TwoWayResponse ISimpleService.TwoWay(TwoWayRequest req)
 {
     Debug.Print("OneWay X=" + req.X + ", Y=" + req.Y);
     // return sum of x and y
     TwoWayResponse resp = new TwoWayResponse();
     resp.Sum = req.X + req.Y;
     return resp;
 }
 public TwoWayResponse TwoWay(TwoWayRequest req)
 {
     System.Ext.Console.Write("");
     System.Ext.Console.Write("TwoWay request X = " + req.X.ToString() + " Y = " + req.Y.ToString());
     int Sum = req.X + req.Y;
     TwoWayResponse resp = new TwoWayResponse();
     resp.Sum = Sum;
     System.Ext.Console.Write("Sum = " + req.X.ToString() + " + " + req.Y.ToString() + " = " + Sum.ToString());
     return resp;
 }
        public TwoWayResponse TwoWay(TwoWayRequest req)
        {
            System.Ext.Console.Write("");
            System.Ext.Console.Write("TwoWay request X = " + req.X.ToString() + " Y = " + req.Y.ToString());
            int            Sum  = req.X + req.Y;
            TwoWayResponse resp = new TwoWayResponse();

            resp.Sum = Sum;
            System.Ext.Console.Write("Sum = " + req.X.ToString() + " + " + req.Y.ToString() + " = " + Sum.ToString());
            return(resp);
        }
Пример #8
0
 public static void Main()
 {
     using (SimpleServiceClientProxy client = new SimpleServiceClientProxy())
     {
         client.ServiceEndpoint = FindFirst(client.DiscoveryClient,
                                            c_serviceTypeName,
                                            c_namespaceUri);
         TwoWayRequest req = new TwoWayRequest();
         req.X = 3;
         req.Y = 4;
         TwoWayResponse resp = client.TwoWayRequest(req);
         Debug.Print("TwoWayRequest " + req.X + "+" + req.Y + "=" + resp.Sum);
     }
 }
Пример #9
0
        public override void WriteObject(XmlWriter writer, object graph)
        {
            TwoWayRequest TwoWayRequestField = ((TwoWayRequest)(graph));

            if (WriteParentElement(writer, true, true, graph))
            {
                WriteAnyAttribute(writer, TwoWayRequestField.AnyAttr);
                if (WriteChildElement(writer, "X", true, true, TwoWayRequestField.X))
                {
                    writer.WriteString(XmlConvert.ToString(TwoWayRequestField.X));
                    writer.WriteEndElement();
                }
                if (WriteChildElement(writer, "Y", true, true, TwoWayRequestField.Y))
                {
                    writer.WriteString(XmlConvert.ToString(TwoWayRequestField.Y));
                    writer.WriteEndElement();
                }
                WriteAnyElement(writer, TwoWayRequestField.Any, false);
                writer.WriteEndElement();
            }
            return;
        }
Пример #10
0
 public override object ReadObject(XmlReader reader)
 {
     TwoWayRequest TwoWayRequestField = null;
     if (IsParentStartElement(reader, false, true))
     {
         TwoWayRequestField = new TwoWayRequest();
         TwoWayRequestField.AnyAttr = ReadAnyAttribute(reader);
         reader.Read();
         if (IsChildStartElement(reader, "X", false, true))
         {
             reader.Read();
             TwoWayRequestField.X = XmlConvert.ToInt32(reader.ReadString());
             reader.ReadEndElement();
         }
         if (IsChildStartElement(reader, "Y", false, true))
         {
             reader.Read();
             TwoWayRequestField.Y = XmlConvert.ToInt32(reader.ReadString());
             reader.ReadEndElement();
         }
         TwoWayRequestField.Any = ReadAnyElement(reader, false);
         reader.ReadEndElement();
     }
     return TwoWayRequestField;
 }
Пример #11
0
        public virtual TwoWayResponse TwoWayRequest(TwoWayRequest req)
        {
            // Create request header
            String action;
            action = "http://schemas.example.org/SimpleService/TwoWayRequest";
            WsWsaHeader header;
            header = new WsWsaHeader(action, null, ServiceEndpoint, null, EndpointAddress, null);

            // Create request serializer
            TwoWayRequestDataContractSerializer reqDcs;
            reqDcs = new TwoWayRequestDataContractSerializer("TwoWayRequest", "http://schemas.example.org/SimpleService");

            // Build soap request message
            byte[] soapBuffer = SoapMessageBuilder.BuildSoapMessage(header, reqDcs, req);

            // Send service request
            DpwsHttpClient httpClient;
            httpClient = new DpwsHttpClient();
            DpwsSoapResponse response;
            response = httpClient.SendRequest(soapBuffer, ServiceEndpoint, false, false);

            // Process response
            TwoWayResponseDataContractSerializer respDcs;
            respDcs = new TwoWayResponseDataContractSerializer("TwoWayResponse", "http://schemas.example.org/SimpleService");
            TwoWayResponse resp;
            resp = ((TwoWayResponse)(respDcs.ReadObject(response.Reader)));
            return resp;
        }
        /// <summary>
        /// Method runs a loop waiting for Hello events. When on is received method probes, resolves
        /// and Get's device service information and calls 1way, 2way methods and subscribes to SimpleEvent
        /// and IntegerEvent and waits for them to fire. When they do Unsubscribe is called on the events
        /// and the receive hello's flag is reset.
        /// </summary>
        public void Run()
        {
            // Create Event handlers
            m_simpleServiceClient.ByeEvent += new ByeEventHandler(m_simpleControl_ByeEvent);
            m_simpleServiceClient.HelloEvent += new HelloEventHandler(m_simpleControl_HelloEvent);
            m_simpleServiceClient.SubscriptionEndEvent += new SubscriptionEndEventHandler(m_simpleControl_SubscriptionEndEvent);
            bool firstPass = true;

            bool twoWayAttach = false;

            DpwsServiceTypes typeProbes = new DpwsServiceTypes();
            typeProbes.Add(new DpwsServiceType("SimpleDeviceType", "http://schemas.example.org/SimpleService"));

            // Continuous run loop
            while (true)
            {
                if (firstPass && !m_inDiscovery)
                {
                    m_inDiscovery = true;
                    DpwsServiceDescriptions descs = m_simpleServiceClient.DiscoveryClient.Probe(typeProbes, 3, 5000);

                    for (int i = 0; i < descs.Count; i++)
                    {
                        DpwsServiceDescription desc = descs[i];

                        if (desc.XAddrs != null && desc.XAddrs.Length > 0)
                        {
                            if (CheckConnection(desc.ServiceTypes, desc.Endpoint.Address.AbsoluteUri)) break;
                        }
                    }
                    m_inDiscovery = false;
                }

                // If hello was received and a SimpleService device was found. SeletedService will not be null.
                // Process until Bye is received.
                if (m_deviceSelected.WaitOne(5000, false))
                {
                    // If this is the first time through the loop for this device subscribe to events
                    if (firstPass)
                    {
                        try
                        {
                            // Test service host call
                            System.Ext.Console.Write("Testing Host service...");
                            DpwsSubscribeRequest subReq;
                            subReq = new DpwsSubscribeRequest(m_eventingServiceClient.EventSources["SimpleEvent"], m_eventSubscriptionAddress, m_eventingServiceClient.TransportAddress, "PT1H", null);
                            m_simpleEventSubscription = m_eventingServiceClient.EventingClient.Subscribe(subReq);
                            subReq = new DpwsSubscribeRequest(m_eventingServiceClient.EventSources["IntegerEvent"], m_eventSubscriptionAddress, m_eventingServiceClient.TransportAddress, "PT1H", null);
                            m_integerEventSubscription = m_eventingServiceClient.EventingClient.Subscribe(subReq);

                            firstPass = false;
                        }
                        catch
                        {
                            m_deviceSelected.Reset();
                        }
                    }

                    // Make 1Way and 2Way service calls
                    if (m_deviceSelected.WaitOne(0, false))
                    {
                        try
                        {
                            PrintMetadataInfo();

                            System.Ext.Console.Write("");
                            System.Ext.Console.Write(">>>>>>>>>>>>> Sending 1way(10) request to: " + m_selectedService.ThisDevice.FriendlyName);
                            m_simpleServiceClient.OneWay(new OneWayRequest());
                        }
                        catch (Exception e)
                        {
                            firstPass = true;
                            m_deviceSelected.Reset();
                            System.Ext.Console.Write("");
                            System.Ext.Console.Write("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! OneWay method failed. " + e.Message);
                        }
                    }

                    if (m_deviceSelected.WaitOne(0, false))
                    {
                        int x = System.Math.Abs(m_random.Next()) % 100;
                        int y = System.Math.Abs(m_random.Next()) % 100;

                        System.Ext.Console.Write("");
                        System.Ext.Console.Write(">>>>>>>>>>>>> Sending 2way(" + x.ToString() + ", " + y.ToString() + ") request to: " + m_selectedService.ThisDevice.FriendlyName);
                        try
                        {
                            TwoWayRequest req = new TwoWayRequest();
                            req.X = x;
                            req.Y = y;

                            TwoWayResponse resp = m_simpleServiceClient.TwoWay(req);
                            if (resp.Sum == 0)
                            {
                                System.Ext.Console.Write("");
                                System.Ext.Console.Write("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2way method did not receive a valid response.");
                            }
                            else
                            {
                                System.Ext.Console.Write("");
                                System.Ext.Console.Write("<<<<<<<<<<<<< 2way response returned " + resp.Sum);
                            }
                        }
                        catch (Exception e)
                        {
                            firstPass = true;
                            m_deviceSelected.Reset();
                            System.Ext.Console.Write("");
                            System.Ext.Console.Write("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TwoWay method failed. " + e.Message);
                        }
                    }

                    // Make 1wayattach or a 2wayattach service calls
                    if (m_deviceSelected.WaitOne(0, false))
                    {
                        if (!twoWayAttach)
                        {
                            // create an instance of the help icon test object
                            HelpIcon helpIcon = new HelpIcon();

                            System.Ext.Console.Write("");
                            System.Ext.Console.Write(">>>>>>>>>>>>> Sending 1wayattach request to: " + m_selectedService.ThisDevice.FriendlyName);
                            try
                            {
                                OneWayAttachmentRequest req = new OneWayAttachmentRequest();
                                req.Param = helpIcon.Data.ToArray();
                                m_attachmentServiceClient.OneWayAttachment(req);
                            }
                            catch (Exception e)
                            {
                                firstPass = true;
                                m_deviceSelected.Reset();
                                System.Ext.Console.Write("");
                                System.Ext.Console.Write("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1wayattach method failed: " + e.Message);
                            }
                        }
                        else
                        {
                            // create an instance of the help icon test object
                            HelpIcon helpIcon = new HelpIcon();

                            System.Ext.Console.Write("");
                            System.Ext.Console.Write(">>>>>>>>>>>>> Sending 2wayattach request to: " + m_selectedService.ThisDevice.FriendlyName);
                            try
                            {
                                TwoWayAttachmentRequest req = new TwoWayAttachmentRequest();
                                req.Param = helpIcon.Data.ToArray();
                                TwoWayAttachmentResponse resp = m_attachmentServiceClient.TwoWayAttachment(req);

                                System.Ext.Console.Write("");
                                System.Ext.Console.Write("<<<<<<<<<<<<< Sending 2wayattach request succeeded");
                            }
                            catch (Exception e)
                            {
                                firstPass = true;
                                m_deviceSelected.Reset();
                                System.Ext.Console.Write("");
                                System.Ext.Console.Write("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TwoWay method failed. " + e.Message);
                            }
                        }

                        twoWayAttach = !twoWayAttach;
                    }
                }
                else
                {
                    firstPass = true;
                }

                GC.WaitForPendingFinalizers();
            }
        }