Example #1
0
 public SimpleDeviceHost(ProtocolVersion version) : base(version)
 {
     // Add ServiceNamespace. Set ServiceID and ServiceTypeName
     ServiceNamespace = new WsXmlNamespace("sim", "http://schemas.example.org/SimpleService");
     ServiceID = "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51";
     ServiceTypeName = "SimpleDeviceType";
 }
        /// <summary>
        /// Creates an instance of the Subscription manager class.
        /// </summary>
        /// <remarks>
        /// The device manages an instance of this class on behalf of the device. A device developer
        /// must use the static Device.SubScriptionMgr.FireEvent method to fire events from an event
        /// source.
        /// </remarks>
        public DpwsWseSubscriptionMgr(Binding binding, ProtocolVersion version)
        {
            m_binding = binding.Clone();
            m_version = version;

            m_reqChannel = binding.CreateClientChannel(new ClientBindingContext(version));
        }
        public SimpleServiceClientProxy(Binding binding, ProtocolVersion version) : 
                base(binding, version)
        {

            // Set client endpoint address
            m_requestChannel = m_localBinding.CreateClientChannel(new ClientBindingContext(m_version));
        }
 public HelloWCFService(ProtocolVersion v)
     : base(v)
 {
     // Add ServiceNamespace. Set ServiceID and ServiceTypeName
     ServiceNamespace = new WsXmlNamespace("h", "http://schemas.example.org/HelloWCF");
     ServiceID = "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51";
     ServiceTypeName = "HelloWCFDeviceType";
 }
 /// <summary>
 /// Creates and instance of the DpwsDiscoveryClient class.
 /// </summary>
 internal DpwsDiscoveryClient(DpwsClient parent, ProtocolVersion v)
 {
     // Discovery Port defined by http://www.iana.org/assignments/port-numbers as Web Services for Devices
     m_discoResponsePort = 5357;
     m_receiveTimeout    = 5000;
     m_version = v;
     m_parent = parent;
     m_random = new Random();
 }
 /// <summary>
 /// Creates and instance of the DpwsDiscoveryClient class.
 /// </summary>
 internal DpwsDiscoveryClient(DpwsClient parent, ProtocolVersion v)
 {
     // Arbitrary available port value for default ws-discovery response port
     m_discoResponsePort = 15357;
     m_receiveTimeout    = 5000;
     m_version = v;
     m_parent = parent;
     m_random = new Random();
 }
        //--//

        /// <summary>
        /// Creates and instance of the HostedService class.
        /// </summary>
        public DpwsHostedService(ProtocolVersion v)
        {
            m_threadLock        = new object();
            m_endpointRefs      = new WsWsaEndpointRefs();
            m_serviceOperations = new WsServiceOperations();
            m_eventSources      = new DpwsWseEventSources();
            m_prefixCounter     = 0;
            m_blockingCall      = true;
            m_version           = v;
        }
        // Constructor sets service properties and defines operations
        public AttachmentService(ProtocolVersion version) : base(version)
        {
            // Add ServiceNamespace. Set ServiceID and ServiceTypeName
            ServiceNamespace = new WsXmlNamespace("att", AttNamespace);
            ServiceID = "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b92";
            ServiceTypeName = "AttachmentService";

            // Add service operations
            ServiceOperations.Add(new WsServiceOperation(AttNamespace, "OneWayAttachment"));
            ServiceOperations.Add(new WsServiceOperation(AttNamespace, "TwoWayAttachmentRequest"));
        }
        //--//

        public DpwsDiscoClientService(DpwsClient client, ProtocolVersion version)
        {
            m_client = client;
            m_threadLock = new object();
            m_version = version;

            m_messageCheck = new WsMessageCheck();

            // Add discovery Hello ServiceOperations
            m_discoCallbacks = new WsServiceOperations();
            m_discoCallbacks.Add(new WsServiceOperation(m_version.DiscoveryNamespace, "Hello"));
            m_discoCallbacks.Add(new WsServiceOperation(m_version.DiscoveryNamespace, "Bye"));
        }
        // Constructor sets service properties and adds event sources
        public EventingService(ProtocolVersion version) : base(version)
        {
            // Add ServiceNamespace. Set ServiceID and ServiceTypeName
            ServiceNamespace = new WsXmlNamespace("evnt", "http://schemas.example.org/EventingService");
            ServiceID = "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b91";
            ServiceTypeName = "EventingService";
            
            // Add event sources
            EventSources.Add(new DpwsWseEventSource("evnt", "http://schemas.example.org/EventingService", "SimpleEvent"));
            EventSources.Add(new DpwsWseEventSource("evnt", "http://schemas.example.org/EventingService", "IntegerEvent"));
            this.AddEventServices();

            // Start the event simulator
            StartEventSimulator();
        }
        public EventingServiceClientProxy(Binding binding, ProtocolVersion version, IEventingServiceCallback callbackHandler) : 
                base(binding, version)
        {
            // Set the client callback implementation property
            m_eventHandler = callbackHandler;

            // Set client endpoint address
            m_requestChannel = m_localBinding.CreateClientChannel(new ClientBindingContext(m_version));

            // Add client callback operations and event source types
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/EventingService", "SimpleEvent"));
            EventSources.Add(new DpwsServiceType("SimpleEvent", "http://schemas.example.org/EventingService"));
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/EventingService", "IntegerEvent"));
            EventSources.Add(new DpwsServiceType("IntegerEvent", "http://schemas.example.org/EventingService"));
        }
Example #12
0
        // Constructor sets service properties and defines operations and adds event sources
        public SimpleService(ProtocolVersion version) : base(version)
        {
            // Add ServiceNamespace. Set ServiceID and ServiceTypeName
            ServiceNamespace = new WsXmlNamespace("sim", "http://schemas.example.org/SimpleService");
            ServiceID = "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b90";
            ServiceTypeName = "SimpleService";

            // Add service operations
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "OneWay"));
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "TwoWayRequest"));

            // Add event sources
            DpwsWseEventSource SimpleEvent = new DpwsWseEventSource("sim", "http://schemas.example.org/EventingService", "SimpleEvent");
            EventSources.Add(SimpleEvent);
            this.AddEventServices();
        }
        public ServiceHelloWCF(IServiceHelloWCF service, ProtocolVersion version) : 
                base(version)
        {
            // Set the service implementation properties
            m_service = service;

            // Set base service properties
            ServiceNamespace = new WsXmlNamespace("ser", "http://localhost/ServiceHelloWCF");
            ServiceID = "urn:uuid:1ef46552-0532-4e74-8c9c-635e126924a1";
            ServiceTypeName = "ServiceHelloWCF";

            // Add service types here
            ServiceOperations.Add(new WsServiceOperation("http://localhost/ServiceHelloWCF/IServiceHelloWCF", "HelloWCF"));

            // Add event sources here
        }
        public EventingService(ProtocolVersion version) : 
                base(version)
        {

            // Set base service properties
            ServiceNamespace = new WsXmlNamespace("eve", "http://schemas.example.org/EventingService");
            ServiceID = "urn:uuid:cd35d6ba-3e2f-440b-bc2f-b7c375dc6536";
            ServiceTypeName = "EventingService";

            // Add service types here

            // Add event sources here
            EventSources.Add(new DpwsWseEventSource("eve", "http://schemas.example.org/EventingService", "SimpleEvent"));
            EventSources.Add(new DpwsWseEventSource("eve", "http://schemas.example.org/EventingService", "IntegerEvent"));
            this.AddEventServices();
        }
        public IServiceHelloWCF(IIServiceHelloWCF service, ProtocolVersion version) : 
                base(version)
        {
            // Set the service implementation properties
            m_service = service;

            // Set base service properties
            ServiceNamespace = new WsXmlNamespace("ise", "http://localhost/ServiceHelloWCF");
            ServiceID = "urn:uuid:f4c30207-c2cb-493c-8a44-776c1e0ecc7e";
            ServiceTypeName = "IServiceHelloWCF";

            // Add service types here
            ServiceOperations.Add(new WsServiceOperation("http://localhost/ServiceHelloWCF/IServiceHelloWCF", "HelloWCF"));

            // Add event sources here
        }
        public AttachmentService(IAttachmentService service, ProtocolVersion version) : 
                base(version)
        {
            // Set the service implementation properties
            m_service = service;

            // Set base service properties
            ServiceNamespace = new WsXmlNamespace("att", "http://schemas.example.org/AttachmentService");
            ServiceID = "urn:uuid:6a97c339-8d5e-4c2e-a8a3-d4d109983c8a";
            ServiceTypeName = "AttachmentService";

            // Add service types here
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/AttachmentService", "OneWayAttachment"));
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/AttachmentService", "TwoWayAttachment"));

            // Add event sources here
        }
        public SimpleService(ISimpleService service, ProtocolVersion version) : 
                base(version)
        {
            // Set the service implementation properties
            m_service = service;

            // Set base service properties
            ServiceNamespace = new WsXmlNamespace("sim", "http://schemas.example.org/SimpleService");
            ServiceID = "urn:uuid:5b0dd589-9f8c-4c23-b797-01ca3092b1ed";
            ServiceTypeName = "SimpleService";

            // Add service types here
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "OneWay"));
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "TwoWay"));
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "TypeCheck"));
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "AnyCheck"));

            // Add event sources here
        }
Example #18
0
        public TestService(string guid, ProtocolVersion version) : base(version)
        {
            // Add ServiceNamespace. Set ServiceID and ServiceTypeName
            ServiceNamespace = new WsXmlNamespace("sim", "http://schemas.example.org/SimpleService");
            ServiceID = "urn:uuid:" + guid;
            ServiceTypeName = "TestService";

            // Add additional namesapces if needed
            // example: Namespaces.Add("someprefix", "http://some/Namespace");

            // Add service operations
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "OneWay"));
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "TwoWayRequest"));

            // Add event sources
            DpwsWseEventSource SimpleEvent = new DpwsWseEventSource("sim", "http://schemas.example.org/EventingService", "SimpleEvent");
            EventSources.Add(SimpleEvent);
            this.AddEventServices();
        }
        //--//
        
        public DpwsDeviceDiscoService(ProtocolVersion v) : base(v)
        {
            string wsdNamespace = v.DiscoveryNamespace;

            // Set the service type name to internal to hide from discovery services
            ServiceTypeName = "Internal";

            // Set service namespace
            ServiceNamespace = new WsXmlNamespace(WsNamespacePrefix.Wsd, wsdNamespace);

            // Set endpoint address
            EndpointAddress = v.DiscoveryWellKnownAddress;

            // Add Discovery service operations
            ServiceOperations.Add(new WsServiceOperation(wsdNamespace, "Probe"));
            ServiceOperations.Add(new WsServiceOperation(wsdNamespace, "Resolve"));

            m_discovery = new DpwsDeviceDiscovery(v);
        }
        public EventingServiceClientProxy(Binding binding, ProtocolVersion version, IEventingServiceCallback callbackHandler) : 
                base(binding, version)
        {
            // Set the client callback implementation property
            m_eventHandler = callbackHandler;

            // Set client endpoint address
            m_requestChannel = m_localBinding.CreateClientChannel(new ClientBindingContext(m_version));

            // Add client callback operations and event source types
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/EventingService", "SimpleEvent"));
            EventSources.Add(new DpwsServiceType("SimpleEvent", "http://schemas.example.org/EventingService"));
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/EventingService", "IntegerEvent"));
            EventSources.Add(new DpwsServiceType("IntegerEvent", "http://schemas.example.org/EventingService"));

            // Add eventing SubscriptionEnd ServiceOperations. By default Subscription End call back to this client
            ServiceOperations.Add(new WsServiceOperation(WsWellKnownUri.WseNamespaceUri, "SubscriptionEnd"));

            this.StartEventListeners();
        }
        public IDataAccessService(IIDataAccessService service, ProtocolVersion version) : 
                base(version)
        {
            // Set the service implementation properties
            m_service = service;

            // Set base service properties
            ServiceNamespace = new WsXmlNamespace("ida", "http://tempuri.org/");
            ServiceID = "urn:uuid:358c10f8-ff82-4e9e-977d-236f02d75e7d";
            ServiceTypeName = "IDataAccessService";

            // Add service types here
            ServiceOperations.Add(new WsServiceOperation("http://tempuri.org/IDataAccessService", "GetData"));
            ServiceOperations.Add(new WsServiceOperation("http://tempuri.org/IDataAccessService", "SetData"));
            ServiceOperations.Add(new WsServiceOperation("http://tempuri.org/IDataAccessService", "SetFileInfo"));
            ServiceOperations.Add(new WsServiceOperation("http://tempuri.org/IDataAccessService", "GetNestedData"));
            ServiceOperations.Add(new WsServiceOperation("http://tempuri.org/IDataAccessService", "SetNestedData"));

            // Add event sources here
        }
        /// <summary>
        /// Create an instance of a SubscriptionEndEvent arguments object.
        /// </summary>
        internal SubscriptionEndEventArgs(WsMessage msg, ProtocolVersion version)
        {
            // Retrieve the Identifier
            WsWsaHeader header = msg.Header;
            XmlReader reader = msg.Reader;


            this.Identifier = header.Any.GetNodeValue("Identifier", version.EventingNamespace);

            reader.ReadStartElement("SubscriptionEnd", version.EventingNamespace);

            if (reader.IsStartElement("SubscriptionManager", version.EventingNamespace))
            {
                this.SubscriptionManager = new WsWsaEndpointRef(reader, version.AddressingNamespace);
            }

            this.SubscriptionID = this.SubscriptionManager.RefParameters.GetNodeValue("Identifier", version.EventingNamespace);

            if (this.SubscriptionID == null || this.Identifier == null) // both need to be there
            {
                throw new XmlException();
            }
        }
Example #23
0
        /// <summary>
        /// Creates an instance of a DpwsClient class with a specified eventing callback port number.
        /// </summary>
        public DpwsClient(Binding localBinding, ProtocolVersion v)
        {
            m_threadLock               = new object();
            m_eventClient              = new DpwsEventingClient(v);
            m_mexClient                = new DpwsMexClient(v);
            m_eventCallbacks           = new WsServiceOperations();
            m_callbackServiceEndpoints = new WsServiceEndpoints();
            m_blockingCall             = true;
            m_ignoreRequestFromThisIP  = true;
            m_localBinding             = localBinding;
            m_version                  = v;

            m_discoClient = new DpwsDiscoveryClient(this, v);

            // Add the Hello and Bye discovery disco services
            ClientDiscoveryService = new DpwsDiscoClientService(this, v);

            // Start a Udp discovery service host
            WsUdpServiceHost.Instance.AddServiceEndpoint(ClientDiscoveryService);
            WsUdpServiceHost.Instance.IgnoreRequestFromThisIP = m_ignoreRequestFromThisIP;
            WsUdpServiceHost.Instance.MaxThreadCount = 5;
            WsUdpServiceHost.Instance.Start(new ServerBindingContext(v));
        }
        /// <summary>
        /// Creates an instance of a DpwsClient class with a specified eventing callback port number.
        /// </summary>
        public DpwsClient(Binding localBinding, ProtocolVersion v)
        {
            m_threadLock               = new object();
            m_eventClient              = new DpwsEventingClient(v);
            m_mexClient                = new DpwsMexClient(v);
            m_eventCallbacks           = new WsServiceOperations();
            m_callbackServiceEndpoints = new WsServiceEndpoints();
            m_blockingCall             = true;
            m_ignoreRequestFromThisIP  = true;
            m_localBinding             = localBinding;
            m_version                  = v;

            m_discoClient = new DpwsDiscoveryClient(this, v);

            // Add the Hello and Bye discovery disco services
            ClientDiscoveryService = new DpwsDiscoClientService(this, v);

            // Start a Udp discovery service host
            WsUdpServiceHost.Instance.AddServiceEndpoint(ClientDiscoveryService);
            WsUdpServiceHost.Instance.IgnoreRequestFromThisIP = m_ignoreRequestFromThisIP;
            WsUdpServiceHost.Instance.MaxThreadCount = 5;
            WsUdpServiceHost.Instance.Start(new ServerBindingContext(v));

            // Add eventing SubscriptionEnd ServiceOperations. By default Subscription End call back
            // to this client
            ServiceOperations.Add(new WsServiceOperation(WsWellKnownUri.WseNamespaceUri, "SubscriptionEnd"));

            // Add callbacks implemented by this client
            m_callbackServiceEndpoints.Add(this);

            // Start the Http service host
            m_httpServiceHost = new WsHttpServiceHost(m_localBinding, m_callbackServiceEndpoints);
            m_httpServiceHost.MaxThreadCount = m_callbackServiceEndpoints.Count;
            m_httpServiceHost.Start(new ServerBindingContext(v));
            System.Ext.Console.Write("Http service host started...");
        }
        public static XmlReader ParseSoapMessage(byte[] soapMessage, ref WsWsaHeader header, ProtocolVersion version)
        {
            MemoryStream requestStream = new MemoryStream(soapMessage);
            XmlReader reader = XmlReader.Create(requestStream);
            header = new WsWsaHeader();

            try
            {
                reader.ReadStartElement("Envelope", WsWellKnownUri.SoapNamespaceUri);
#if DEBUG
                int depth = reader.Depth;
#endif
                header.ParseHeader(reader, version);
#if DEBUG
                Microsoft.SPOT.Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                reader.ReadStartElement("Body", WsWellKnownUri.SoapNamespaceUri);

            }
            catch (XmlException e)
            {
                reader.Close();
                throw new WsFaultException(header, WsFaultType.XmlException, e.ToString());
            }

            return reader;
        }
        internal DpwsServiceDescriptions(XmlReader reader, DpwsServiceDescription.ServiceDescriptionType type, ProtocolVersion v, IPEndPoint remoteEP)
        {
            m_threadLock          = new object();
            m_serviceDescriptions = new ArrayList();            

            Microsoft.SPOT.Debug.Assert(type == DpwsServiceDescription.ServiceDescriptionType.ProbeMatch ||
                type == DpwsServiceDescription.ServiceDescriptionType.ResolveMatch);

            String collectionName, itemName;
            if (type == DpwsServiceDescription.ServiceDescriptionType.ProbeMatch)
            {
                collectionName = "ProbeMatches";
                itemName = "ProbeMatch";
            }
            else
            {
                collectionName = "ResolveMatches";
                itemName = "ResolveMatch";
            }

            reader.ReadStartElement(collectionName, v.DiscoveryNamespace);

            while (reader.IsStartElement(itemName, v.DiscoveryNamespace))
            {
#if DEBUG
                int depth = reader.Depth;
#endif
                m_serviceDescriptions.Add(new DpwsServiceDescription(reader, type, v, remoteEP));
#if DEBUG
                Microsoft.SPOT.Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
            }

            if (type == DpwsServiceDescription.ServiceDescriptionType.ResolveMatch && m_serviceDescriptions.Count > 1)
            {
                // Per schema, there can only be 1 resolve match
                throw new XmlException();
            }

            XmlReaderHelper.SkipAllSiblings(reader); // xs:any
            reader.ReadEndElement(); // collectionName
        }
        // Creates an instance of the metadata services class.
        public DpwsDeviceMexService(ProtocolVersion v) : base(v)
        {
            Init();

            m_response = new DpwsWsxMetdataResponse(v);
        }
        /// <summary>
        /// Initializes the device. This method builds the colletion of internal device services, sets
        /// the devices transport address and adds DPWS required namespaces to the devices namespace collection.
        /// </summary>
        public static void Initialize(Binding binding, ProtocolVersion v)
        {
            m_binding = binding;

            string addr = binding.Transport.EndpointAddress.AbsoluteUri;
            int index = addr.LastIndexOf('/');
            m_address = "urn:uuid:" + addr.Substring(index+1);

            SubscriptionManager = new DpwsWseSubscriptionMgr(binding, v);

            if(v != null) 
            {            
                // Add disco services to udp service endpoints collection
                m_discoveryService = new DpwsDeviceDiscoService(v);
                m_discoGreeting = new DpwsDiscoGreeting(v);
                // Create a new udp service host and add the discovery endpoints
                WsUdpServiceHost.Instance.AddServiceEndpoint(m_discoveryService);
            }

            // Add metadata get service endpoint
            m_discoMexService = new DpwsDeviceMexService(v);
            m_hostedServices.Add(m_discoMexService);

            // Add direct probe service endpoint
            if(m_discoveryService != null) m_hostedServices.Add(m_discoveryService);

            // Create a new http service host and add hosted services endpoints
            m_httpServiceHost = new WsHttpServiceHost(m_binding, m_hostedServices);

            System.Ext.Console.Write("IP Address: " + WsNetworkServices.GetLocalIPV4Address());
        }
        //--//

        /// <summary>
        /// Creates an instance of a DpwsDiscoClientProcessor class.
        /// </summary>
        public DpwsDiscoClientProcessor(ProtocolVersion version)
        {
            m_version = version;
        }
 internal WsSoapMessageWriter(ProtocolVersion version) { m_version = version; }