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();
        }
예제 #2
0
 public LibraryController(ILibraryView view)
 {
     this.state = InnerState.INITIAL;
     binding = new WS2007HttpBinding(new HttpTransportBindingConfig(new Uri("http://" + IP_ADDRESS + "/LibraryWS/Service.svc")));
     View = view;
     View.Controller = this;
     View.ShowLoginPage();
 }
        public void Run()
        {

            Uri remoteEp = new Uri("http://localhost:8084/ServiceHelloWCF.svc");
            WS2007HttpBinding binding = new WS2007HttpBinding(new HttpTransportBindingConfig(remoteEp));

            ProtocolVersion ver = new ProtocolVersion11();
            // To enable WSDiscoveryApril2005 and Soap12WSAddressingAugust2004
            //ProtocolVersion ver = new ProtocolVersion10();

            /// ProtocolVersion11 can be used if the corresponding WCF desktop server application
            /// WcfServer uses wsHttpBinding instead of the custom binding "Soap11AddressingBinding"
            m_clientProxy = new ServiceHelloWCFClientProxy(binding, ver);

            m_clientProxy.IgnoreRequestFromThisIP = false;

            if (!Discover(m_clientProxy))
            {
                Debug.Print("Discovery failed, trying direct address");
            }

            HelloWCF req = new HelloWCF();
            req.name = "World";

            try
            {
                HelloWCFResponse resp = m_clientProxy.HelloWCF(req);

                Debug.Print("\n\n*****************");
                Debug.Print(resp.HelloWCFResult);
                Debug.Print("*****************\n\n");
            }
            catch (WsFaultException ex)
            {
                Debug.Print("DPWS Fault: " + ex.Message);
            }
            finally
            {
                m_clientProxy.Dispose();
            }
        }
        public void Run()
        {

            Uri remoteEp = new Uri("http://localhost:8001/ServiceHelloWCF");
            WS2007HttpBinding binding = new WS2007HttpBinding(new HttpTransportBindingConfig(remoteEp));

            /// ProtocolVersion11 can be used if the corresponding WCF desktop server application
            /// WcfServer uses wsHttpBinding instead of the custom binding "Soap11AddressingBinding"
            m_clientProxy = new ServiceHelloWCFClientProxy(binding, new ProtocolVersion11());

            m_clientProxy.IgnoreRequestFromThisIP = false;

            if (!Discover(m_clientProxy))
            {
                Debug.Print("Discovery failed, trying direct address");
                m_clientProxy.EndpointAddress = "http://localhost:8084/319D0A4D-2253-47DC-AC4A-C1951FF6667D";
            }

            HelloWCF req = new HelloWCF();
            req.name = "World";

            try
            {
                HelloWCFResponse resp = m_clientProxy.HelloWCF(req);

                Debug.Print("\n\n*****************");
                Debug.Print(resp.HelloWCFResult);
                Debug.Print("*****************\n\n");
            }
            catch (WsFaultException ex)
            {
                Debug.Print("DPWS Fault: " + ex.Message);
            }

            m_clientProxy.Dispose();
        }
        ManualResetEvent m_deviceSelected; // Tells the app a device is selected

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

            m_version = new ProtocolVersion11();
            // To enable WSDiscoveryApril2005 and Soap12WSAddressingAugust2004
            //m_version = new ProtocolVersion10();
            m_eventSubscriptionAddress = "";
            m_deviceEndpointAddress = "";

            m_simpleServiceClient = new SimpleServiceClientProxy(new WS2007HttpBinding(), m_version);

            // Event handling requires that we have a defined port (other than 8084)
            WS2007HttpBinding binding = new WS2007HttpBinding(new HttpTransportBindingConfig("urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b07", 15338, true));
            m_eventingServiceClient = new EventingServiceClientProxy(binding, m_version, new EventingClientImplementation());

            m_attachmentServiceClient = new AttachmentServiceClientProxy(new WS2007HttpBinding(), m_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();
        }
예제 #6
0
        private void TestMtomService()
        {
            try
            {
                WS2007HttpBinding binding = new WS2007HttpBinding(
                    new HttpTransportBindingConfig(new Uri("http://*****:*****@"A bedtime story is a traditional form of storytelling, where a story is told to a child at bedtime to prepare them for sleep.
Bedtime stories have many advantages, for parents/adults and children alike. The fixed routine of a bedtime story before sleeping has a relaxing effect, and the soothing voice of a person telling a story makes the child fall asleep more easily. The emotional aspect creates a bond between the storyteller and the listener, often a parent and child.
Bedtime stories can be read from a book, or rather, fictional stories made up by the storyteller. The stories are mostly rather short, between one and five minutes, and have a happy ending. A different form of bedtime reading is using longer stories, but dividing them up, thus creating cliffhangers. Children will look forward to their bedtime story, and a fixed routine is installed.
");
                m_proxy.SetData(req);

                GetData req2 = new GetData();
                // get bytes < 1000 to test Base64
                req2.value = 0;
                GetDataResponse resp = m_proxy.GetData(req2);
                Debug.Print(new string(System.Text.UTF8Encoding.UTF8.GetChars(resp.GetDataResult.Data)));
                
                // to get data > 1000 bytes to test mtom
                req2.value = 1;
                resp = m_proxy.GetData(req2);
                Debug.Print(new string(System.Text.UTF8Encoding.UTF8.GetChars(resp.GetDataResult.Data)));

                // to get data > 1000 (non-char) bytes to test mtom
                req2.value = 2;
                resp = m_proxy.GetData(req2);
                for (int i = 0; i < resp.GetDataResult.Data.Length; i++)
                {
                    if ((byte)i != resp.GetDataResult.Data[i])
                    {
                        Debug.Print("FAILURE!!!!! expected incrementing data byte values");
                        break;
                    }
                }

                SetNestedData req3 = new SetNestedData();
                req3.data = new schemas.datacontract.org.WcfMtomService.NestedClass();
                req3.data.MTData = new schemas.datacontract.org.WcfMtomService.MtomData();
                req3.data.MTData.Data = System.Text.UTF8Encoding.UTF8.GetBytes( @"A bedtime story is a traditional form of storytelling, where a story is told to a child at bedtime to prepare them for sleep." );
                req3.data.MyData = System.Text.UTF8Encoding.UTF8.GetBytes(@"Bedtime stories have many advantages, for parents/adults and children alike. The fixed routine of a bedtime story before sleeping has a relaxing effect, and the soothing voice of a person telling a story makes the child fall asleep more easily. The emotional aspect creates a bond between the storyteller and the listener, often a parent and child.");
                m_proxy.SetNestedData(req3);

                GetNestedData req4 = new GetNestedData();

                GetNestedDataResponse resp8 = m_proxy.GetNestedData(req4);
                Debug.Print(new string(System.Text.UTF8Encoding.UTF8.GetChars(resp8.GetNestedDataResult.MyData)));
                for (int i = 0; i < resp8.GetNestedDataResult.MTData.Data.Length; i++)
                {
                    if ((byte)i != resp8.GetNestedDataResult.MTData.Data[i])
                    {
                        Debug.Print("FAILURE!!!!! expected incrementing data byte values");
                        break;
                    }
                }


                SetFileInfo sfi = new SetFileInfo();

                sfi.files = new schemas.datacontract.org.WcfMtomService.ArrayOfFileInfo();

                sfi.files.FileInfo = new schemas.datacontract.org.WcfMtomService.FileInfo[2];

                sfi.files.FileInfo[0] = new schemas.datacontract.org.WcfMtomService.FileInfo();
                sfi.files.FileInfo[0].Name = "MyBook";
                sfi.files.FileInfo[0].Size = 340;
                sfi.files.FileInfo[1] = new schemas.datacontract.org.WcfMtomService.FileInfo();
                sfi.files.FileInfo[1].Name = "MyBook2";
                sfi.files.FileInfo[1].Size = 341;

                m_proxy.SetFileInfo(sfi);
            }
            catch (System.IO.IOException)
            {
                // Is the web service down???
                Debug.Print("Warning: could not connect to stocks web service");
            }
            finally
            {
                if (m_proxy != null) m_proxy.Dispose();
            }
        }
예제 #7
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;
        }
예제 #8
0
        /// <summary>
        /// Global eventing Subscribe stub.
        /// </summary>
        /// <param name="header">Header object.</param>
        /// <param name="reader">An XmlReader positioned at the begining of the Subscribe request body element.</param>
        /// <param name="serviceEndpoints">A Collection of serviceEndpoints used to determine what services contain the event source specified in the filter.</param>
        /// <returns>Byte array containing a Subscribe response.</returns>
        internal WsMessage Subscribe(WsWsaHeader header, XmlReader reader, WsServiceEndpoints serviceEndpoints)
        {
            WsMessage msg = null;

            // Parse Subscribe Request
            /////////////////////////////
            DpwsWseEventSink eventSink = new DpwsWseEventSink();
            try
            {
                reader.ReadStartElement("Subscribe", WsWellKnownUri.WseNamespaceUri);

                if (reader.IsStartElement("EndTo", WsWellKnownUri.WseNamespaceUri))
                {
                    eventSink.EndTo = new WsWsaEndpointRef(reader, m_version.AddressingNamespace);
                }

                reader.ReadStartElement("Delivery", WsWellKnownUri.WseNamespaceUri);
                if (reader.IsStartElement("NotifyTo", WsWellKnownUri.WseNamespaceUri))
                {
                    eventSink.NotifyTo = new WsWsaEndpointRef(reader, m_version.AddressingNamespace);
                }
                else
                {
                    throw new WsFaultException(header, WsFaultType.WseDeliverModeRequestedUnavailable);
                }

                reader.ReadEndElement();

                if (reader.IsStartElement("Expires", WsWellKnownUri.WseNamespaceUri))
                {
                    long expires = new WsDuration(reader.ReadElementString()).DurationInSeconds;

                    if (expires > 0)
                    {
                        eventSink.Expires = expires;
                    }
                    else
                    {
                        throw new WsFaultException(header, WsFaultType.WseInvalidExpirationTime);
                    }
                }
                else
                {
                    // Never Expires
                    eventSink.Expires = -1;
                }

                if (reader.IsStartElement("Filter", WsWellKnownUri.WseNamespaceUri))
                {
                    if (reader.MoveToAttribute("Dialect") == false || reader.Value != m_version.WsdpNamespaceUri + "/Action")
                    {
                        throw new WsFaultException(header, WsFaultType.WseFilteringRequestedUnavailable);
                    }

                    reader.MoveToElement();

                    String filters = reader.ReadElementString();

                    if (filters != String.Empty)
                    {
                        eventSink.Filters = filters.Split(' ');
                    }
                }

                XmlReaderHelper.SkipAllSiblings(reader);

                reader.ReadEndElement(); // Subscribe
            }
            catch (XmlException e)
            {
                throw new WsFaultException(header, WsFaultType.WseInvalidMessage, e.ToString());
            }

            // Parse urn:uuid from the To address
            string endpointAddress = FixToAddress(header.To);

            // Build a temporary collection of device services that match the specified endpoint address.
            WsServiceEndpoints matchingServices = new WsServiceEndpoints();
            for (int i = 0; i < serviceEndpoints.Count; ++i)
            {
                if (serviceEndpoints[i].EndpointAddress == endpointAddress)
                    matchingServices.Add(serviceEndpoints[i]);
            }

            // For each service with a matching endpoint and event sources add an event sink to the
            // event source collection
            for (int i = 0; i < matchingServices.Count; ++i)
            {
                DpwsWseEventSources eventSources = ((DpwsHostedService)matchingServices[i]).EventSources;

                // Set the EventSinkID
                eventSink.ID = "urn:uuid:" + Guid.NewGuid().ToString();

                // If subscribing to all event sources
                if (eventSink.Filters == null)
                {
                    int count = eventSources.Count;
                    for (int ii = 0; i < count; i++)
                    {
                        DpwsWseEventSource eventSource = eventSources[ii];
                        eventSink.StartTime = DateTime.Now.Ticks;
                        Uri key =  eventSink.NotifyTo.Address;

                        if(m_evtChannelLookup.Contains(key))
                        {
                            EventChannel ec = (EventChannel)m_evtChannelLookup[key];
                            eventSink.RequestChannel = ec.Channel;
                            Interlocked.Increment(ref ec.RefCount);
                        }
                        else
                        {
                            WS2007HttpBinding binding = new WS2007HttpBinding(new HttpTransportBindingConfig(eventSink.NotifyTo.Address, m_persistEventConnections));
                            eventSink.RequestChannel = binding.CreateClientChannel(new ClientBindingContext(m_version));

                            if(m_persistEventConnections)
                            {
                                eventSink.RequestChannel.Open();
                            }

                            m_evtChannelLookup[key] = new EventChannel(eventSink.RequestChannel);
                        }
                        eventSource.EventSinks.Add(eventSink);
                    }
                }
                else
                {
                    // If subscribing to a specific event based on an event filter.
                    DpwsWseEventSource eventSource;
                    string[] filterList = eventSink.Filters;
                    int length = filterList.Length;
                    for (int ii = 0; i < length; i++)
                    {
                        if ((eventSource = eventSources[filterList[ii]]) != null)
                        {
                            eventSink.StartTime = DateTime.Now.Ticks;
                            Uri key =  eventSink.NotifyTo.Address;

                            if(m_evtChannelLookup.Contains(key))
                            {
                                EventChannel ec = (EventChannel)m_evtChannelLookup[key];
                                eventSink.RequestChannel = ec.Channel;
                                Interlocked.Increment(ref ec.RefCount);
                            }
                            else
                            {
                                WS2007HttpBinding binding = new WS2007HttpBinding(new HttpTransportBindingConfig(eventSink.NotifyTo.Address, m_persistEventConnections));
                                eventSink.RequestChannel = binding.CreateClientChannel(new ClientBindingContext(m_version));

                                if(m_persistEventConnections)
                                {
                                    eventSink.RequestChannel.Open();
                                }

                                m_evtChannelLookup[key] = new EventChannel(eventSink.RequestChannel);
                            }
                            eventSource.EventSinks.Add(eventSink);
                        }
                        else
                        {
                            throw new Exception("Event source " + filterList[ii] + " was not found.");
                        }
                    }
                }
            }

            // Generate Response
            //////////////////////////
            using(XmlMemoryWriter xmlWriter = XmlMemoryWriter.Create())
            {
                WsWsaHeader responseHeader = new WsWsaHeader(
                    WsWellKnownUri.WseNamespaceUri + "/SubscribeResponse",  // Action
                    header.MessageID,                                       // RelatesTo
                    header.ReplyTo.Address.AbsoluteUri,                     // To
                    null, null, null);                                      // ReplyTo, From, Any

                msg = new WsMessage(responseHeader, null, WsPrefix.Wse, null, 
                    new WsAppSequence(Device.AppSequence, Device.SequenceID, Device.MessageID));

                WsSoapMessageWriter smw = new WsSoapMessageWriter(m_version);
                smw.WriteSoapMessageStart(xmlWriter, msg);

                // write body
                xmlWriter.WriteStartElement(WsNamespacePrefix.Wse, "SubscribeResponse", null);
                xmlWriter.WriteStartElement(WsNamespacePrefix.Wse, "SubscriptionManager", null);
                xmlWriter.WriteStartElement(WsNamespacePrefix.Wsa, "Address", null);
                // Create a uri. Use the path (by default will be a uuid) for the sub manager endpoint
                Uri subMgrUri = new Uri(((DpwsHostedService)matchingServices[0]).EndpointAddress);
                xmlWriter.WriteString("http://" + Device.IPV4Address + ":" + Device.Port + "/" + subMgrUri.AbsolutePath);
                xmlWriter.WriteEndElement(); // End Address
                xmlWriter.WriteStartElement(WsNamespacePrefix.Wsa, "ReferenceParameters", null);
                xmlWriter.WriteStartElement(WsNamespacePrefix.Wse, "Identifier", null);
                xmlWriter.WriteString(eventSink.ID);
                xmlWriter.WriteEndElement(); // End Identifier
                xmlWriter.WriteEndElement(); // End ReferenceParameters
                xmlWriter.WriteEndElement(); // End SubscriptionManager
                xmlWriter.WriteStartElement(WsNamespacePrefix.Wse, "Expires", null);
                xmlWriter.WriteString(new WsDuration(eventSink.Expires).DurationString);
                xmlWriter.WriteEndElement(); // End Expires
                xmlWriter.WriteEndElement(); // End SubscribeResponse

                smw.WriteSoapMessageEnd(xmlWriter);

                // Return stream buffer
                msg.Body = xmlWriter.ToArray();
            }

            return msg;
        }