Beispiel #1
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);
        }
        private bool Discover(ServiceHelloWCFClientProxy proxy)
        {
            DpwsServiceTypes typeProbes = new DpwsServiceTypes();
            typeProbes.Add(new DpwsServiceType("IServiceHelloWCF", "http://localhost/ServiceHelloWCF"));

            DpwsServiceDescriptions descs = proxy.DiscoveryClient.Probe(typeProbes, 1, 20000);

            if(descs.Count > 0)
            {
                proxy.EndpointAddress = descs[0].XAddrs[0];
                return true;
            }

            return false;
        }
Beispiel #3
0
        /// <summary>
        /// Looks for devices that host a service identified by its type and namespace. 
        /// It returns the transport address of the first matching service.
        /// </summary>
        public static string FindFirst(DpwsDiscoveryClient discoveryClient, string serviceTypeName, string namespaceUri)
        {
            if (discoveryClient == null)
                throw new ArgumentNullException();
            if (serviceTypeName == null)
                throw new ArgumentNullException();
            if (namespaceUri == null)
                throw new ArgumentNullException();

            Debug.Print("Discovering service devices...");
            // Define search criterias
            DpwsServiceType serviceType = new DpwsServiceType(serviceTypeName, namespaceUri);
            DpwsServiceTypes filters = new DpwsServiceTypes();
            filters.Add(serviceType);
            // Probe for devices
            DpwsServiceDescriptions probeMatches = discoveryClient.Probe(filters);
            if (probeMatches != null && probeMatches.Count > 0)
            {
                // Remember transport address of the first device
                string deviceTransportAddress = probeMatches[0].XAddrs[0];
                // Request metadata to get the desired service and its ID
                DpwsMexClient mexClient = new DpwsMexClient();
                DpwsMetadata metadata = mexClient.Get(deviceTransportAddress);
                // Check host service
                DpwsMexService host = metadata.Relationship.Host;
                if (host != null) // has host service
                {
                    if (host.ServiceTypes[serviceTypeName] != null)
                        return host.EndpointRefs[0].Address.AbsoluteUri;
                }
                // Check hosted services
                DpwsMexServices hostedServices = metadata.Relationship.HostedServices;
                if (hostedServices != null)
                {
                    for (int i = 0; i < hostedServices.Count; ++i)
                    {
                        DpwsMexService hostedService = hostedServices[i];
                        if (hostedService.ServiceTypes[serviceTypeName] != null)
                            return hostedService.EndpointRefs[0].Address.AbsoluteUri;
                    }
                }
            }
            Debug.Print("No service found.");
            return null;
        }
        public void PrintProbeMatchInfo()
        {
            Debug.Print("Discovering service devices...");
            // Define search criterias
            DpwsServiceType serviceType = new DpwsServiceType("SimpleServiceType2", // type name
                                                              "http://schemas.sample.org/SimpleService2"); // namespace URI
            DpwsServiceTypes filters = new DpwsServiceTypes();
            filters.Add(serviceType);
            // Probe for devices
            DpwsServiceDescriptions probeMatches = this.DiscoveryClient.Probe(filters);
            if (probeMatches != null)
            {
                for (int i = 0; i < probeMatches.Count; ++i)
                {
                    DpwsServiceDescription probeMatch = probeMatches[i];
                    // Print probe match information
                    Debug.Print("");
                    Debug.Print("Probe Match:");

                    Debug.Print("Endpoint Address = " + probeMatch.Endpoint.Address.AbsoluteUri);

                    Debug.Print("Types:");
                    for (int t = 0; t < probeMatch.ServiceTypes.Count; ++t)
                    {
                        DpwsServiceType matchType = probeMatch.ServiceTypes[t];
                        Debug.Print("\tName = " + matchType.TypeName);
                        Debug.Print("\tNamespace = " + matchType.NamespaceUri);
                        Debug.Print("");
                    }

                    Debug.Print("XAddrs:");
                    foreach (string xaddr in probeMatch.XAddrs)
                        Debug.Print("\tTransport Address = " + xaddr);

                    Debug.Print("Metadata Version = " + probeMatch.MetadataVersion);
                }
            }
            else
                Debug.Print("No service device found.");
        }
        void SimpleServiceClient_HelloEvent(object obj, DpwsServiceDescription helloEventArgs)
        {
            m_receivedHelloEvent = true;
            DpwsMetadata m_mexDetails = null;

            try
            {
                // Print Hello information
                //Log.Comment("");
                //Log.Comment("SimpleService received a hello request.");
                ////Log.Comment("Endpoint address: " + helloEventArgs.Endpoint.Address.AbsoluteUri);
                string types = "";
                int count = helloEventArgs.ServiceTypes.Count;
                for (int i = 0; i < count; i++)
                {
                    DpwsServiceType type = helloEventArgs.ServiceTypes[i];
                    types += "NamespaceUri: " + type.NamespaceUri + " " + "TypeName: " + type.TypeName + "\n";
                }
                ////Log.Comment("Types: " + types);

                if (helloEventArgs.XAddrs != null)
                {
                    foreach (String xaddr in helloEventArgs.XAddrs)
                    {
                        ////Log.Comment("Xaddrs: " + xaddr);
                    }
                }

                ////Log.Comment("Metadata version: " + helloEventArgs.MetadataVersion);
                ////Log.Comment("");

                // Probe for services. For each valid probe match, print service information.
                DpwsServiceType searchType = new DpwsServiceType("SimpleService", "http://schemas.example.org/SimpleService");
                DpwsServiceTypes searchTypes = new DpwsServiceTypes();

                searchTypes.Add(searchType);

                // Accept the first 10 found within the first 10 seconds
                DpwsServiceDescriptions probeMatches = this.DiscoveryClient.Probe(searchTypes, 1, 10000);

                // retry
                if (probeMatches.Count == 0)
                {
                    probeMatches = this.DiscoveryClient.Probe(searchTypes, 1, 10000);
                }

                if (probeMatches != null)
                {
                    // Print the probe match information
                    ////Log.Comment("**********************");
                    ////Log.Comment("ProbeMatches received: " + probeMatches.Count);
                    int probeMatchCount = probeMatches.Count;
                    for (int i = 0; i < probeMatchCount; i++)
                    {
                        DpwsServiceDescription probeMatch = probeMatches[i];
                        ////Log.Comment("");
                        ////Log.Comment("ProbeMatch:");
                        ////Log.Comment("  Endpoint Address = " + probeMatch.Endpoint.Address.AbsoluteUri);
                        ////Log.Comment("  Types:");

                        PrintServiceTypes(probeMatch.ServiceTypes);

                        //////Log.Comment("  Xaddrs:");
                        //foreach (string xaddr in probeMatch.XAddrs)
                        //    //Log.Comment("    TransportAddress = " + xaddr);
                        ////Log.Comment("  Metadata Version = " + probeMatch.MetadataVersion);

                        // Resolve this endpoint
                        DpwsServiceDescription resolveMatch = this.DiscoveryClient.Resolve(probeMatch.Endpoint.Address.AbsoluteUri, 10000);
                        if (resolveMatch != null)
                        {
                            // Print resolve match information
                            ////Log.Comment("");
                            ////Log.Comment("ResolveMatch:");
                            ////Log.Comment("  Endpoint Address = " + resolveMatch.Endpoint.Address.AbsoluteUri);
                            ////Log.Comment("  Types:");

                            PrintServiceTypes(resolveMatch.ServiceTypes);

                            ////Log.Comment("  Xaddrs:");
                            //foreach (string xaddr in resolveMatch.XAddrs)
                            //    //Log.Comment("    TransportAddress = " + xaddr);

                            //Log.Comment("  Metadata Version = " + resolveMatch.MetadataVersion);

                            // For each Xaddr, get metadata
                            foreach (string xaddr in resolveMatch.XAddrs)
                            {
                                // Call Get
                                m_mexDetails = this.MexClient.Get(xaddr);

                                if (m_mexDetails == null)
                                {

                                    ////Log.Comment("Get failed. Address: " + xaddr);
                                }
                                else
                                {
                                    m_getMex = true;

                                    // Display metadata information
                                    ////Log.Comment("  Metadata:");
                                    ////Log.Comment("    ThisModel:");
                                    ////Log.Comment("      Manufacturer: " + m_mexDetails.ThisModel.Manufacturer);
                                    ////Log.Comment("      ManufacturerUrl: " + m_mexDetails.ThisModel.ManufacturerUrl);
                                    ////Log.Comment("      ModelName: " + m_mexDetails.ThisModel.ModelName);
                                    ////Log.Comment("      ModelNumber: " + m_mexDetails.ThisModel.ModelNumber);
                                    ////Log.Comment("      ModelUrl: " + m_mexDetails.ThisModel.ModelUrl);
                                    ////Log.Comment("      PresentationUrl: " + m_mexDetails.ThisModel.PresentationUrl);
                                    ////Log.Comment("    ThisDevice:");
                                    ////Log.Comment("      FirmwareVersion: " + m_mexDetails.ThisDevice.FirmwareVersion);
                                    ////Log.Comment("      FriendlyName: " + m_mexDetails.ThisDevice.FriendlyName);
                                    ////Log.Comment("      SerialNumber: " + m_mexDetails.ThisDevice.SerialNumber);
                                    if (m_mexDetails.Relationship.Host != null)
                                    {
                                        ////Log.Comment("    Host:");
                                        ////Log.Comment("      Service ID: " + m_mexDetails.Relationship.Host.ServiceID);
                                        ////Log.Comment("      Address: " + m_mexDetails.Relationship.Host.EndpointRefs[0].Address.AbsoluteUri);
                                        ////Log.Comment("      Types:");

                                        PrintServiceTypes(m_mexDetails.Relationship.Host.ServiceTypes);
                                    }
                                    if (m_mexDetails.Relationship.HostedServices != null)
                                    {
                                        ////Log.Comment("    HostedServices:");
                                        int hostedServiceCount = m_mexDetails.Relationship.HostedServices.Count;
                                        for (int j = 0; j < hostedServiceCount; j++)
                                        {
                                            DpwsMexService hostedService = m_mexDetails.Relationship.HostedServices[j];

                                            ////Log.Comment("      Service ID: " + hostedService.ServiceID);
                                            ////Log.Comment("      Address: " + hostedService.EndpointRefs[0].Address.AbsoluteUri);
                                            ////Log.Comment("      Types:");

                                            PrintServiceTypes(hostedService.ServiceTypes);
                                        }
                                    }
                                }
                            }

                            if (m_mexDetails != null)
                            {
                                // Look for the SimpleService in the HostedServices collection, create an HTTP
                                // client, call TwoWayRequest on the service endpoint, and display the result.
                                int hostedServiceCount = m_mexDetails.Relationship.HostedServices.Count;
                                for (int j = 0; j < hostedServiceCount; j++)
                                {
                                    DpwsMexService hostedService = m_mexDetails.Relationship.HostedServices[j];

                                    if (hostedService.ServiceTypes["SimpleService"] != null)    // found a SimpleService endpoint
                                    {
                                        string endpointAddress = hostedService.EndpointRefs[0].Address.AbsoluteUri;
                                        ////Log.Comment("");
                                        ////Log.Comment("Calling TwoWayRequest at endpoint: " + endpointAddress);

                                        // Create HttpClient and send request
                                        int x = 150;
                                        int y = 180;

                                        byte[] TwoWayRequest = Build2wayRequest(x, y, endpointAddress);

                                        
                                        //Log.Comment(new String(System.Text.Encoding.UTF8.GetChars(TwoWayRequest)));
                                        //DpwsHttpClient httpClient = new DpwsHttpClient();
                                        //DpwsSoapResponse response = httpClient.SendRequest(TwoWayRequest, endpointAddress, false, false);

                                        WsHttpClient httpClient = new WsHttpClient(m_version);
                                        WsMessage response = httpClient.SendRequest(new WsMessage(null, TwoWayRequest, WsPrefix.Wsdp), new Uri(endpointAddress));
                                        
                                        if (response != null)       // got a response
                                        {
                                            try
                                            {
                                                int sum = Parse2WayResponse(response.Header, response.Reader);
                                                //Log.Comment("");
                                                //Log.Comment("Received sum of " + sum.ToString() + " from " + endpointAddress);
                                                if ((x + y) == sum)
                                                    m_twoWay = true;
                                            }
                                            finally
                                            {
                                                response.Reader.Close();
                                            }
                                        }
                                    }
                                }
                            }
                            //Log.Comment("");
                        }
                    }
                }
            }
            finally
            {
            }

            if (m_mexDetails != null)
            {
                arHello.Set();
            }
        }
 // Helper method to print names and namespaces of service types
 private void PrintServiceTypes(DpwsServiceTypes types)
 {
     int typeCount = types.Count;
     for (int i = 0; i < typeCount; i++)
     {
         DpwsServiceType serviceType = types[i];
         //Log.Comment("    Name = " + serviceType.TypeName);
         //Log.Comment("    Namespace = " + serviceType.NamespaceUri);
     }
 }
        bool CheckConnection(DpwsServiceTypes servTypes, string servAddr)
        {
            try
            {
                bool simpleDeviceTypeFound = false;
                string types = "";
                for (int i = 0; i < servTypes.Count; ++i)
                {
                    if (servTypes[i].TypeName == "SimpleDeviceType")
                        simpleDeviceTypeFound = true;
                    types += "NamespaceUri: " + servTypes[i].NamespaceUri + " " + "TypeName: " + servTypes[i].TypeName + "\n";
                }
                System.Ext.Console.Write("Types: " + types);
                System.Ext.Console.Write("");

                // If this is not a SimplDeviceType don't discover
                if (simpleDeviceTypeFound == false)
                {
                    System.Ext.Console.Write("");
                    System.Ext.Console.Write("Discovery will only resolve SimpleDeviceType services.");
                }

                // Get SimpleService metadata
                DpwsMetadata deviceMetadata = m_discoClient.GetSimpleService(servAddr);
                if (deviceMetadata != null)
                {
                    SelectedService = deviceMetadata;
                    m_deviceSelected.Set();
                    m_deviceEndpointAddress = servAddr;

                    return true;
                }
            }
            catch
            {
            }

            return false;
        }
        /// <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();
            }
        }
Beispiel #9
0
        /// <summary>
        /// Probe for a SimpleService endpoint.
        /// </summary>
        /// <param name="serviceAddress">A string containing the address of the simple service to find.</param>
        /// <returns>
        /// A DpwsMetadata object containing details about a SimpleService, null if
        /// a SImpleService is not found.
        /// </returns>
        public DpwsMetadata GetSimpleService(string serviceAddress)
        {
            // Resolve the service address
            m_dpwsClient.DiscoveryClient.ReceiveTimeout = 10000;
            DpwsServiceDescription resolveMatch = m_dpwsClient.DiscoveryClient.Resolve(serviceAddress);

            // Display results
            string serviceEndpoint = null;
            string targetService = null;
            if (resolveMatch != null)
            {
                // Print resolve match information
                System.Ext.Console.Write("");
                System.Ext.Console.Write("ResolveMatch:");
                System.Ext.Console.Write("  Endpoint Address = " + resolveMatch.Endpoint.Address);
                System.Ext.Console.Write("  Types:");
                targetService = resolveMatch.Endpoint.Address.AbsoluteUri;
                for (int i = 0; i < resolveMatch.ServiceTypes.Count; ++i)
                {
                    System.Ext.Console.Write("    Name = " + resolveMatch.ServiceTypes[i].TypeName);
                    System.Ext.Console.Write("    Namespace = " + resolveMatch.ServiceTypes[i].NamespaceUri);
                }
                System.Ext.Console.Write("  Xaddrs:");
                foreach (string xaddr in resolveMatch.XAddrs)
                {
                    System.Ext.Console.Write("    TransportAddress = " + xaddr);

                    // Since there's no support for IPV6 look for IPV4 address
                    if (xaddr.IndexOf(':') != -1)
                    {
                        serviceEndpoint = xaddr;
                    }
                }

                System.Ext.Console.Write("  Metadata Version = " + resolveMatch.MetadataVersion);
            }
            else
            {
                System.Ext.Console.Write("");
                System.Ext.Console.Write("SimpleDeviceType at address: " + serviceAddress + " failed to resolve. Discovery aborted");
                return null;
            }

            // Mae sure we got an address
            if (serviceEndpoint == null)
            {
                System.Ext.Console.Write("");
                System.Ext.Console.Write("Resolve did not send an IPV4 xaddr. Discovery aborted.");
            }

            // Send DirectedProbe
            DpwsMetadata m_mexDetails = null;

            // Create an empty search types collection
            DpwsServiceTypes searchTypes = new DpwsServiceTypes();

            // Build a SimpleDeviceType search type
            DpwsServiceType searchType1 = new DpwsServiceType("SimpleService", "http://schemas.example.org/SimpleService");
            searchTypes.Add(searchType1);
            
            // Get the SimpleDeviceType service details
            // Note: Uncomment the next line to test DirectedProbe to any MF Dpws service
            // DpwsServiceDescriptions probeMatches = m_dpwsClient.DiscoveryClient.DirectedProbe(serviceEndpoint, m_dpwsClient.DiscoveryClient.DiscoVersion.WellKnownAddress, searchTypes);
            // Note: Uncomment the next line to test against a DiscoveryProxy
            // DpwsServiceDescriptions probeMatches = m_dpwsClient.DiscoveryClient.DirectedProbe(serviceEndpoint, targetService, searchTypes);
            DpwsServiceDescriptions probeMatches = m_dpwsClient.DiscoveryClient.Probe(searchTypes);
            if (probeMatches != null && probeMatches.Count > 0)
            {
                // Select the probe match
                DpwsServiceDescription probeMatch = probeMatches[0];

                // Note: Uncoment the following line to test DirectedResolve against any MF Dpws Service.
                // DpwsServiceDescription resolveMatch1 = m_dpwsClient.DiscoveryClient.DirectedResolve(probeMatch.XAddrs[0], m_dpwsClient.DiscoveryClient.DiscoVersion.WellKnownAddress, serviceAddress);

                // Print the probe match information
                System.Ext.Console.Write("**********************");
                System.Ext.Console.Write("ProbeMatch received: " + probeMatches.Count);
                System.Ext.Console.Write("");
                System.Ext.Console.Write("ProbeMatch:");
                System.Ext.Console.Write("  Endpoint Address = " + probeMatch.Endpoint.Address);
                System.Ext.Console.Write("  Types:");
                for (int i = 0; i < probeMatch.ServiceTypes.Count; ++i)
                {
                    System.Ext.Console.Write("    Name = " + probeMatch.ServiceTypes[i].TypeName);
                    System.Ext.Console.Write("    Namespace = " + probeMatch.ServiceTypes[i].NamespaceUri);
                }
                System.Ext.Console.Write("  Xaddrs:");
                foreach (string xaddr in probeMatch.XAddrs)
                    System.Ext.Console.Write("    TransportAddress = " + xaddr);
                System.Ext.Console.Write("  Metadata Version = " + probeMatch.MetadataVersion);
            }

            // If we had a probe match store the service endpoint and get metadata
            if (probeMatches != null)
            {
                m_dpwsClient.EndpointAddress = serviceAddress;
                m_mexDetails = m_dpwsClient.MexClient.Get(serviceEndpoint);

                if (m_mexDetails == null)
                {
                    System.Ext.Console.Write("");
                    System.Ext.Console.Write("Get did not receive metadata. Discovery aborted.");
                    return null;
                }
                // Display metadata information
                System.Ext.Console.Write("  Metadata:");
                System.Ext.Console.Write("    ThisModel:");
                System.Ext.Console.Write("      Manufacturer: " + m_mexDetails.ThisModel.Manufacturer);
                System.Ext.Console.Write("      ManufacturerUrl: " + m_mexDetails.ThisModel.ManufacturerUrl);
                System.Ext.Console.Write("      ModelName: " + m_mexDetails.ThisModel.ModelName);
                System.Ext.Console.Write("      ModelNumber: " + m_mexDetails.ThisModel.ModelNumber);
                System.Ext.Console.Write("      ModelUrl: " + m_mexDetails.ThisModel.ModelUrl);
                System.Ext.Console.Write("      PresentationUrl: " + m_mexDetails.ThisModel.PresentationUrl);
                System.Ext.Console.Write("    ThisDevice:");
                System.Ext.Console.Write("      FirmwareVersion: " + m_mexDetails.ThisDevice.FirmwareVersion);
                System.Ext.Console.Write("      FriendlyName: " + m_mexDetails.ThisDevice.FriendlyName);
                System.Ext.Console.Write("      SerialNumber: " + m_mexDetails.ThisDevice.SerialNumber);
                if (m_mexDetails.Relationship.Host != null)
                {
                    System.Ext.Console.Write("    Host:");
                    System.Ext.Console.Write("      Service ID: " + m_mexDetails.Relationship.Host.ServiceID);
                    System.Ext.Console.Write("      Address: " + m_mexDetails.Relationship.Host.EndpointRefs[0].Address.AbsoluteUri);
                    System.Ext.Console.Write("      Types:");
                    for (int i = 0; i < m_mexDetails.Relationship.Host.ServiceTypes.Count; ++i)
                    {
                        DpwsServiceType serviceType = m_mexDetails.Relationship.Host.ServiceTypes[i];
                        System.Ext.Console.Write("        Name: " + serviceType.TypeName);
                        System.Ext.Console.Write("        NamespaceUri: " + serviceType.NamespaceUri);
                    }
                }
                if (m_mexDetails.Relationship.HostedServices != null)
                {
                    System.Ext.Console.Write("    HostedServices:");
                    for (int i = 0; i < m_mexDetails.Relationship.HostedServices.Count; ++i)
                    {
                        DpwsMexService hostedService = m_mexDetails.Relationship.HostedServices[i];
                        System.Ext.Console.Write("      Service ID: " + hostedService.ServiceID);
                        System.Ext.Console.Write("      Address: " + hostedService.EndpointRefs[0].Address.AbsoluteUri);
                        System.Ext.Console.Write("      Types:");
                        for (int ii = 0; ii < hostedService.ServiceTypes.Count; ++ii)
                        {
                            System.Ext.Console.Write("        Type name: " + hostedService.ServiceTypes[ii].TypeName);
                            System.Ext.Console.Write("        NamespaceUri: " + hostedService.ServiceTypes[ii].NamespaceUri);
                        }
                    }
                }
            }
            return m_mexDetails;
        }
Beispiel #10
0
        public MFTestResults ClientTest_DpwsServiceTypes()
        {
            /// <summary>
            /// 1. Verifies the properties of a DpwsServiceTypes object
            /// 2. Adds elements to it
            /// 3. Re-verifies
            /// 4. Empties the object
            /// 5. Re-verifies
            /// </summary>
            ///
            bool testResult = true;
            try
            {
                DpwsServiceTypes testDSTs = new DpwsServiceTypes();

                if (testDSTs.Count != 0)
                    throw new Exception("Count did not set correctly on new");

                testDSTs.Clear();

                if (testDSTs.Count != 0)
                    throw new Exception("Count did not set correctly after new ... clear");

                String typeName = "typeName";
                String namespaceUri = "namespaceUri";

                DpwsServiceType testDST1 = new DpwsServiceType(typeName, namespaceUri);

                String typeName2 = "typeName2";
                String namespaceUri2 = "namespaceUri2";

                DpwsServiceType testDST2 = new DpwsServiceType(typeName2, namespaceUri2);

                testDSTs.Add(testDST1);

                testDSTs.Add(testDST2);

                if (testDSTs.Count != 2)
                    throw new Exception("Count did not set correctly on new");


                testDSTs.Remove(testDST1);

                if (testDSTs.Count != 1)
                    throw new Exception("Count did not set correctly after remove");

                testDSTs.Clear();

                if (testDSTs.Count != 0)
                    throw new Exception("Count did not set correctly after new ... clear");
            }
            catch (Exception e)
            {
                testResult = false;
                Log.Comment("Incorrect exception caught: " + e.Message);
            }
            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }