ManualResetEvent m_deviceSelected; // Tells the app a device is selected

        public TestApplication()
        {
            m_threadLock = new object();
            m_inOperation = false;
            m_deviceSelected = new ManualResetEvent(false);

            ProtocolVersion version = new ProtocolVersion10();

            WS2007HttpBinding binding = new WS2007HttpBinding( new HttpTransportBindingConfig("urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b06", 15337));
            m_simpleServiceClient = new SimpleServiceClientProxy(binding, new ProtocolVersion10());

            binding = new WS2007HttpBinding(new HttpTransportBindingConfig("urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b07", 15338));
            m_eventingServiceClient = new EventingServiceClientProxy(binding, version, new EventingClientImplementation());

            binding = new WS2007HttpBinding(new HttpTransportBindingConfig("urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b08", 15339));
            m_attachmentServiceClient = new AttachmentServiceClientProxy(binding, version);

            // Turn listening to this IP on
            m_simpleServiceClient.IgnoreRequestFromThisIP = false;
            m_eventingServiceClient.IgnoreRequestFromThisIP = false;
            m_attachmentServiceClient.IgnoreRequestFromThisIP = false;

            m_discoClient = new DiscoClient(m_simpleServiceClient);

            m_random = new Random();
        }
Beispiel #2
0
        public MFTestResults DiscoveryTest_DpwsServiceDescription()
        {
            /// <summary>
            /// 1. Verifies each of the proerties of a ByeEventArgs object
            /// 2. Sets and re-verifies for simple properties.
            /// </summary>
            ///

            ProtocolVersion v = new ProtocolVersion10();
            bool testResult = true;
            try
            {
                WsWsaEndpointRef ep = new WsWsaEndpointRef(new System.Uri(v.AnonymousUri));
                DpwsServiceTypes st = new DpwsServiceTypes();
                DpwsServiceDescription testBEA = new DpwsServiceDescription(ep, st);

                Log.Comment("Endpoint");
                if (testBEA.Endpoint != null)
                    if (testBEA.Endpoint.GetType() != Type.GetType("Ws.Services.WsaAddressing.WsWsaEndpointRef"))
                        throw new Exception("Endpoint wrong type");

                if (testBEA.Endpoint != ep)
                    throw new Exception("Endpoint bad data");

                Log.Comment("MetadataVersion");
                if (testBEA.MetadataVersion != null)
                    if (testBEA.MetadataVersion.GetType() != Type.GetType("System.String"))
                        throw new Exception("MetadataVersion wrong type");

                if (testBEA.MetadataVersion != null)
                    throw new Exception("MetadataVersion bad data");

                Log.Comment("XAddrs");
                if (testBEA.XAddrs != null)
                    if (testBEA.XAddrs.GetType() != Type.GetType("System.String"))
                        throw new Exception("XAddrs wrong type");

                if (testBEA.XAddrs != null)
                    throw new Exception("XAddrs bad data");

                Log.Comment("ServiceTypes");
                if (testBEA.ServiceTypes != null)
                    if (testBEA.ServiceTypes.GetType() != Type.GetType("Dpws.Client.DpwsServiceTypes"))
                        throw new Exception("ServiceTypes wrong type");

                if (testBEA.ServiceTypes.Count != 0)
                    throw new Exception("ServiceTypes bad data");


            }
            catch (Exception e)
            {
                testResult = false;
                Log.Comment("Incorrect exception caught: " + e.Message);
            }
            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
        //SimpleServiceClient client;

        public void Start()
        {
            // Initialize the binding
            string guid = "urn:uuid:18571766-87df-06e2-bb68-5136c48f483a";
            ProtocolVersion version = new ProtocolVersion10();
            Device.Initialize(new WS2007HttpBinding(new HttpTransportBindingConfig(guid, 8084)), version);

            // Set device information
            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 service(s) to the device
            Device.HostedServices.Add(new SimpleService(new SimpleServiceImplementation()));
            EventingService eventingService = new EventingService();
            Device.HostedServices.Add(eventingService);
            Device.HostedServices.Add(new AttachmentService(new AttachmentServiceImplementation()));

            // Add a Dpws client to this device. Uncomment to run a client and device
            //client = new SimpleServiceClient();

            // Set this device property if you want to ignore this clients request
            Device.IgnoreLocalClientRequest = false;

            // Turn console messages on
            Console.Verbose = true;
            
            System.Ext.Console.Write( "Start DPWS device service with endpoint address: '" + Device.EndpointAddress + "'" );

            // Start the device
            ServerBindingContext ctx = new ServerBindingContext(version);
            Device.Start(ctx);
            
            //TEST RESTART CAPABILITY
            //Thread.Sleep(3000);
            //Device.Stop();
            //Thread.Sleep(100);
            //Device.Start(ctx);
            
            // Events cause WsFaultExceptions if loopback messages are used.
            if(Device.IgnoreLocalClientRequest)
            {
                // Create and start EventSimulator
                EventSimulator eventSimulator = new EventSimulator(eventingService);
                eventSimulator.StartEventSimulator();
            }
        }
Beispiel #4
0
        // TwoWayResponse: Build the response for a TwoWayRequest
        public byte[] TwoWayResponse(WsWsaHeader header, int sum)
        {
            ProtocolVersion v = new ProtocolVersion10();

            MemoryStream soapStream = new MemoryStream();
            XmlWriter xmlWriter = XmlWriter.Create(soapStream);

            // Write processing instructions and root element
            xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
            xmlWriter.WriteStartElement("soap", "Envelope", "http://www.w3.org/2003/05/soap-envelope");

            // Write namespaces
            xmlWriter.WriteAttributeString("xmlns", "wsdp", null, v.WsdpNamespaceUri);
            xmlWriter.WriteAttributeString("xmlns", "wsd", null, v.DiscoveryNamespace);
            xmlWriter.WriteAttributeString("xmlns", "wsa", null, v.AddressingNamespace);
            xmlWriter.WriteAttributeString("xmlns", "sim", null, SimpleServiceNamespaceUri);

            // Write header
            xmlWriter.WriteStartElement("soap", "Header", null);
            xmlWriter.WriteStartElement("wsa", "To", null);
            xmlWriter.WriteString(header.From.Address.AbsoluteUri);
            xmlWriter.WriteEndElement();
            xmlWriter.WriteStartElement("wsa", "Action", null);
            xmlWriter.WriteString("http://schemas.example.org/SimpleService/TwoWayResponse");
            xmlWriter.WriteEndElement();
            xmlWriter.WriteStartElement("wsa", "RelatesTo", null);
            xmlWriter.WriteString(header.MessageID);
            xmlWriter.WriteEndElement(); // End RelatesTo
            xmlWriter.WriteStartElement("wsa", "MessageID", null);
            xmlWriter.WriteString("urn:uuid:" + Guid.NewGuid().ToString());
            xmlWriter.WriteEndElement(); // End MessageID
            xmlWriter.WriteEndElement(); // End Header

            // Write body
            xmlWriter.WriteStartElement("soap", "Body", null);
            xmlWriter.WriteStartElement("sim", "TwoWayResponse", null);
            xmlWriter.WriteStartElement("sim", "Sum", null);
            xmlWriter.WriteString(sum.ToString());
            xmlWriter.WriteEndElement(); // End Sun
            xmlWriter.WriteEndElement(); // End TwoWayResponse
            xmlWriter.WriteEndElement(); // End Body

            xmlWriter.WriteEndElement();

            // Create return buffer and close writer
            xmlWriter.Flush();
            byte[] soapBuffer = soapStream.ToArray();
            xmlWriter.Close();

            return soapBuffer;
        }
        /// <summary>
        /// Builds a TwoWayRequest message.
        /// </summary>
        /// <param name="X">The first integer to add.</param>
        /// <param name="Y">The second integer to add.</param>
        /// <param name="endpointAddress">A string containig the service endpoint address.</param>
        /// <returns>The SOAP request.</returns>
        private byte[] Build2wayRequest(int X, int Y, string endpointAddress)
        {
            MemoryStream soapStream = new MemoryStream();
            XmlWriter xmlWriter = XmlWriter.Create(soapStream);

            // Write processing instructions and root element
            xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
            xmlWriter.WriteStartElement("soap", "Envelope", "http://www.w3.org/2003/05/soap-envelope");

            // Write namespaces
            ProtocolVersion10 ver = new ProtocolVersion10();
            xmlWriter.WriteAttributeString("xmlns", "wsa", null, ver.AddressingNamespace);
            xmlWriter.WriteAttributeString("xmlns", "smpl", null, "http://schemas.example.org/SimpleService");

            // Write header
            xmlWriter.WriteStartElement("soap", "Header", null);
            xmlWriter.WriteStartElement("wsa", "To", null);
            xmlWriter.WriteString(endpointAddress);
            xmlWriter.WriteEndElement(); // End To
            xmlWriter.WriteStartElement("wsa", "Action", null);
            xmlWriter.WriteString("http://schemas.example.org/SimpleService/TwoWayRequest");
            xmlWriter.WriteEndElement(); // End Action
            xmlWriter.WriteStartElement("wsa", "From", null);
            xmlWriter.WriteStartElement("wsa", "Address", null);
            xmlWriter.WriteString(EndpointAddress);
            xmlWriter.WriteEndElement(); // End Address
            xmlWriter.WriteEndElement(); // End From
            xmlWriter.WriteStartElement("wsa", "MessageID", null);
            xmlWriter.WriteString("urn:uuid:" + Guid.NewGuid());
            xmlWriter.WriteEndElement(); // End MessageID
            xmlWriter.WriteEndElement(); // End Header

            // Write body
            xmlWriter.WriteStartElement("soap", "Body", null);
            xmlWriter.WriteStartElement("smpl", "TwoWayRequest", null);
            xmlWriter.WriteStartElement("smpl", "X", null);
            xmlWriter.WriteString(X.ToString());
            xmlWriter.WriteEndElement(); // End X
            xmlWriter.WriteStartElement("smpl", "Y", null);
            xmlWriter.WriteString(Y.ToString());
            xmlWriter.WriteEndElement(); // End Y
            xmlWriter.WriteEndElement(); // End TwoWayRequest
            xmlWriter.WriteEndElement(); // End Body

            xmlWriter.WriteEndElement(); // End Document

            // Create return buffer and close xmlWriter
            xmlWriter.Flush();
            byte[] soapBuffer = soapStream.ToArray();
            xmlWriter.Close();

            return soapBuffer;
        }
Beispiel #6
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;
        }
        // TwoWayAttachmentResp: Construct response message for TwoWayAttachmentRequest
        public WsMessage TwoWayAttachmentResp(WsWsaHeader header)
        {
            // Create xmlWriter object
            MemoryStream soapStream = new MemoryStream();
            XmlWriter xmlWriter = XmlWriter.Create(soapStream);

            // Write processing instructions and root element
            xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
            xmlWriter.WriteStartElement("soap", "Envelope", "http://www.w3.org/2003/05/soap-envelope");

            // Write namespaces
            ProtocolVersion10 ver = new ProtocolVersion10();
            xmlWriter.WriteAttributeString("xmlns", "wsa", null, ver.AddressingNamespace);
            xmlWriter.WriteAttributeString("xmlns", "xop", null, WsWellKnownUri.XopNamespaceUri);
            xmlWriter.WriteAttributeString("xmlns", "att", null, "http://schemas.example.org/AttachmentService");

            // Write header
            xmlWriter.WriteStartElement("soap", "Header", null);
            xmlWriter.WriteStartElement("wsa", "To", null);
            xmlWriter.WriteString("http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous");
            xmlWriter.WriteEndElement(); // End To
            xmlWriter.WriteStartElement("wsa", "Action", null);
            xmlWriter.WriteString("http://schemas.example.org/AttachmentService/TwoWayAttachmentResponse");
            xmlWriter.WriteEndElement(); // End Action
            xmlWriter.WriteStartElement("wsa", "RelatesTo", null);
            xmlWriter.WriteString(header.MessageID);
            xmlWriter.WriteEndElement(); // End RelatesTo
            xmlWriter.WriteStartElement("wsa", "MessageID", null);
            xmlWriter.WriteString("urn:uuid:" + Guid.NewGuid().ToString());
            xmlWriter.WriteEndElement(); // End To
            xmlWriter.WriteEndElement(); // End Header

            // write body
            xmlWriter.WriteStartElement("soap", "Body", null);
            xmlWriter.WriteStartElement("att", "TwoWayAttachmentResponse", null);
            xmlWriter.WriteStartElement("att", "Param", null);
            xmlWriter.WriteStartElement("xop", "Include", null);
            xmlWriter.WriteAttributeString("href", "cid:[email protected]");
            xmlWriter.WriteString("");
            xmlWriter.WriteEndElement(); // End Include
            xmlWriter.WriteEndElement(); // End Param
            xmlWriter.WriteEndElement(); // End TwoWayAttachmentResponse
            xmlWriter.WriteEndElement(); // End Body

            xmlWriter.WriteEndElement(); // End Envelope

            // Create return buffer and close writer
            xmlWriter.Flush();
            xmlWriter.Close();

            WsMessage msg = new WsMessage(null, soapStream.ToArray(), WsPrefix.Wse);

            // Clear the hosted service's MTOM body parts collection and build return body parts collection
            // Create and store soap body part (As per spec soap envelope must be first body part)
            WsMtomBodyPart bodyPart = new WsMtomBodyPart();

            // Create and store attachment body part
            bodyPart = new WsMtomBodyPart();
            HelpIcon testIcon = new HelpIcon();
            bodyPart.Content = testIcon.Data;
            bodyPart.ContentID = "<[email protected]>";
            bodyPart.ContentTransferEncoding = "binary";
            bodyPart.ContentType = "application/octet-stream";
            msg.BodyParts.Add(bodyPart);

            // Set the response type so the HTTP processor knows we are sending MTOM
            //MessageType = WsMessageType.Mtom;

            // We are returning the actual response in the hosted service's body parts, so return null
            return msg;
        }
Beispiel #8
0
        public MFTestResults DeviceTest_Start_Stop()
        {
            /// <summary>
            /// 1. Sets up the minimum framework to allow a Device object to start
            /// 2. Sleeps for 10 Seconds
            /// 3. Stops the Device
            /// </summary>
            ///

            bool testResult = true;
            try
            {
                ProtocolVersion ver = new ProtocolVersion10();
                Device.Initialize(new WS2007HttpBinding(new HttpTransportBindingConfig("urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51", 8084)), ver);
                //Device.EndpointAddress = "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51";
                Device.ThisModel.Manufacturer = "Microsoft";
                Device.ThisModel.ManufacturerUrl = "http://www.Microsoft.com/";
                Device.ThisModel.ModelName = "MFDpwsDeviceTests Interop Test Device";
                Device.ThisModel.ModelNumber = "1";
                Device.ThisModel.ModelUrl = "http://www.Microsoft.com/";
                Device.ThisModel.PresentationUrl = "http://www.Microsoft.com/";

                Device.ThisDevice.FriendlyName = "Test Device";
                Device.ThisDevice.FirmwareVersion = "alpha";
                Device.ThisDevice.SerialNumber = "1";

                Device.Host = new TestDeviceHost("3cb0d1ba-cc3a-46ce-b416-212ac2419b51");

                Log.Comment("Starting Device...");
                ServerBindingContext ctx = new ServerBindingContext(ver);
                Device.Start(ctx);
                Log.Comment("Device started, sleeping for 10 seconds...");
                System.Threading.Thread.Sleep(10000);
                Log.Comment("Sleep completed.  Stopping Device...");
                Device.Stop();
                Log.Comment("Device stopped");
            }
            catch (Exception e)
            {
                testResult = false;
                Log.Comment("Incorrect exception caught: " + e.Message);
            }
            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
Beispiel #9
0
        public MFTestResults ClientTest_DpwsClient_Properties()
        {
            /// <summary>
            /// 1. Verifies each of the proerties of a DPWSClient object
            /// 2. Sets and re-verifies for simple properties, checks input checking 
            /// on properties that currently support it.
            /// </summary>
            ///
            ProtocolVersion v = new ProtocolVersion10();
            bool testResult = true;
            int port = 50002;
            DpwsClient testClient = new DpwsClient(new WS2007HttpBinding(new HttpTransportBindingConfig("urn:uuid:" + Guid.NewGuid().ToString(), port)), v);
            try
            {
                Log.Comment("EndpointAddress");
                if (testClient.EndpointAddress != null)
                    if (testClient.EndpointAddress.GetType() != Type.GetType("System.String"))
                        throw new Exception("EndpointAddress wrong type");

                String uri = v.AnonymousUri;
                testClient.EndpointAddress = uri;
                if (testClient.EndpointAddress.GetType() != Type.GetType("System.String"))
                    throw new Exception("EndpointAddress wrong type after set");

                if (testClient.EndpointAddress != uri)
                    throw new Exception("EndpointAddress bad data");

                try
                {
                    testClient.EndpointAddress = " test";
                    throw new Exception("EndpointAddress failed to prevent bad data input");
                }
                catch (System.ArgumentException) { }

                Log.Comment("IgnoreRequestFromThisIP");
                if (testClient.IgnoreRequestFromThisIP.GetType() !=
                    Type.GetType("System.Boolean"))
                    throw new Exception("IgnoreRequestFromThisIP wrong type");

                testClient.IgnoreRequestFromThisIP = true;

                if (!testClient.IgnoreRequestFromThisIP)
                    throw new Exception("IgnoreRequestFromThisIP wrong data after set");

                Log.Comment("ServiceOperations");
                if (testClient.ServiceOperations != null)
                    if (testClient.ServiceOperations.GetType() !=
                        Type.GetType("Ws.Services.WsServiceOperations"))
                        throw new Exception("ServiceOperations wrong type");

                Log.Comment("TransportAddress");
                if (testClient.TransportAddress != null)
                    if (testClient.TransportAddress.GetType() != Type.GetType("System.String"))
                        throw new Exception("TransportAddress wrong type");

            }
            catch (Exception e)
            {
                testResult = false;
                Log.Comment("Incorrect exception caught: " + e.Message);
            }
            finally
            {
                if( testClient != null) 
                    testClient.Dispose();
            }

            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }