public override object ReadObject(XmlReader reader)
 {
     OneWayAttachmentRequest OneWayAttachmentRequestField = null;
     if (IsParentStartElement(reader, false, true))
     {
         OneWayAttachmentRequestField = new OneWayAttachmentRequest();
         OneWayAttachmentRequestField.AnyAttr = ReadAnyAttribute(reader);
         reader.Read();
         if (IsChildStartElement(reader, "Param", true, true))
         {
             reader.Read();
             if (IsAttribute(reader, "href"))
             {
                 string contentID;
                 contentID = reader.Value;
                 reader.MoveToElement();
                 reader.ReadStartElement("Include", "http://www.w3.org/2004/08/xop/include");
                 reader.ReadEndElement();
                 OneWayAttachmentRequestField.Param = GetBodyPartContent(contentID, BodyParts);
             }
             else
             {
                 OneWayAttachmentRequestField.Param = Convert.FromBase64String(reader.ReadString());
                 reader.ReadEndElement();
             }
         }
         OneWayAttachmentRequestField.Any = ReadAnyElement(reader, false);
         reader.ReadEndElement();
     }
     return OneWayAttachmentRequestField;
 }
        public virtual void OneWayAttachment(OneWayAttachmentRequest req)
        {

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

            // Create request serializer
            OneWayAttachmentRequestDataContractSerializer reqDcs;
            reqDcs = new OneWayAttachmentRequestDataContractSerializer("OneWayAttachmentRequest", "http://schemas.example.org/AttachmentService");
            request.Serializer = reqDcs;
            request.Method = "OneWayAttachment";


            // Indicate that this message will use Mtom encoding
            request.BodyParts = new WsMtomBodyParts();

            // Send service request
            m_requestChannel.Open();
            m_requestChannel.RequestOneWay(request);
            m_requestChannel.Close();
        }
        public virtual void OneWayAttachment(OneWayAttachmentRequest req)
        {
            // Create request header
            String action;

            action = "http://schemas.example.org/AttachmentService/OneWayAttachment";
            WsWsaHeader header;

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

            // Create request serializer
            OneWayAttachmentRequestDataContractSerializer reqDcs;

            reqDcs             = new OneWayAttachmentRequestDataContractSerializer("OneWayAttachmentRequest", "http://schemas.example.org/AttachmentService");
            request.Serializer = reqDcs;
            request.Method     = "OneWayAttachment";


            // Indicate that this message will use Mtom encoding
            request.BodyParts = new WsMtomBodyParts();

            // Send service request
            m_requestChannel.Open();
            m_requestChannel.RequestOneWay(request);
            m_requestChannel.Close();
        }
        public override object ReadObject(XmlReader reader)
        {
            OneWayAttachmentRequest OneWayAttachmentRequestField = null;

            if (IsParentStartElement(reader, false, true))
            {
                OneWayAttachmentRequestField         = new OneWayAttachmentRequest();
                OneWayAttachmentRequestField.AnyAttr = ReadAnyAttribute(reader);
                reader.Read();
                if (IsChildStartElement(reader, "Param", true, true))
                {
                    reader.Read();
                    if (IsAttribute(reader, "href"))
                    {
                        string contentID;
                        contentID = reader.Value;
                        reader.MoveToElement();
                        reader.ReadStartElement("Include", "http://www.w3.org/2004/08/xop/include");
                        reader.ReadEndElement();
                        OneWayAttachmentRequestField.Param = GetBodyPartContent(contentID, BodyParts);
                    }
                    else
                    {
                        OneWayAttachmentRequestField.Param = ConvertBase64.FromBase64String(reader.ReadString());
                        reader.ReadEndElement();
                    }
                }
                OneWayAttachmentRequestField.Any = ReadAnyElement(reader, false);
                reader.ReadEndElement();
            }
            return(OneWayAttachmentRequestField);
        }
        public override void WriteObject(XmlWriter writer, object graph)
        {
            OneWayAttachmentRequest OneWayAttachmentRequestField = ((OneWayAttachmentRequest)(graph));

            if (WriteParentElement(writer, true, true, graph))
            {
                WriteAnyAttribute(writer, OneWayAttachmentRequestField.AnyAttr);
                if (WriteChildElement(writer, "Param", true, true, OneWayAttachmentRequestField.Param))
                {
                    BodyParts.Add(CreateNewBodyPart(OneWayAttachmentRequestField.Param, "<1@body>"));
                    writer.WriteStartElement("xop", "Include", "http://www.w3.org/2004/08/xop/include");
                    writer.WriteAttributeString(null, "href", null, "cid:1@body");
                    writer.WriteEndElement();
                    writer.WriteEndElement();
                }
                WriteAnyElement(writer, OneWayAttachmentRequestField.Any, false);
                writer.WriteEndElement();
            }
            return;
        }
 public void OneWayAttachment(OneWayAttachmentRequest req)
 {
     System.Ext.Console.Write("OneWayAttachment received.");
     System.Ext.Console.Write("Attachment size = " + req.Param.Length);
     System.Ext.Console.Write("");
 }
        /// <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();
            }
        }
 public void OneWayAttachment(OneWayAttachmentRequest req)
 {
     System.Ext.Console.Write("OneWayAttachment received.");
     System.Ext.Console.Write("Attachment size = " + req.Param.Length);
     System.Ext.Console.Write("");
 }