/// <summary> /// Creates an instance a DpwsSubscribeRequest class initialized with the service endpoint Address, /// notifyTo callback endpoint address and event duration. /// </summary> /// <param name="subscriptionType">A DpwsServieType object containing a definition of the service being subscripbed to.</param> /// <param name="endpointAddress">A string containing an event source endpoint address.</param> /// <param name="notifyToAddress">A string containing the notifyTo endpoint address.</param> /// <param name="expires"> /// A string containing the subscription expiration time in duration format. If /// null the event does not expire. /// </param> /// <param name="identifier">A WsWsaRefParamter object containing a unique identifier. /// This value will be included in an event messages soap header as a reference parameter. /// This value is not processed by a service it is intended to provide a unique identified /// a client can use for any purpose.</param> /// <remarks> /// This constructor sets the endTo address to null indicating that the notifyTo address should receive /// subscription end messages. A user ID for the event is not set by default. /// </remarks> /// <exception cref="ArgumentException">If duration format is invalid.</exception> public DpwsSubscribeRequest(DpwsServiceType subscriptionType, string endpointAddress, string notifyToAddress, string expires, WsXmlNode identifier) { if (endpointAddress == null) { throw new ArgumentNullException("enpointAddress must not be null."); } if (notifyToAddress == null) { throw new ArgumentNullException("notifyTo must not be null."); } this.SubscriptionType = subscriptionType; this.EndpointAddress = new Uri(endpointAddress); this.NotifyTo = new WsWsaEndpointRef(new Uri(notifyToAddress)); this.EndTo = new WsWsaEndpointRef(new Uri(notifyToAddress)); if (identifier != null) { this.NotifyTo.RefProperties.Add(identifier); this.EndTo.RefProperties.Add(identifier); } if (expires != null) { this.Expires = new WsDuration(expires); } }
public EventingServiceController(string serviceTransportAddress) { this.serviceTransportAddress = serviceTransportAddress; // Set this device property if you want to ignore this service notifications this.IgnoreRequestFromThisIP = false; // Assigning either a static or random endpoint address will // init the transport address of this client which we will use soon this.EndpointAddress = "urn:uuid:" + Guid.NewGuid(); // Adding a event handler this.ServiceOperations.Add(new WsServiceOperation(c_namespaceUri, // namespace "SimpleEvent")); // event (method) name // Subscribe to the event DpwsServiceType subscriptionType = new DpwsServiceType("SimpleEvent", c_namespaceUri); DpwsSubscribeRequest request = new DpwsSubscribeRequest(subscriptionType, // subscription type serviceTransportAddress, // event source address this.TransportAddress, // notify to address null, // expires null // event identifier ); this.EventingClient.Subscribe(request); }
private static void client_HelloEvent(object obj, DpwsServiceDescription helloEventArgs) { // Print Hello event information Debug.Print(""); Debug.Print("Hello Event:"); Debug.Print("Endpoint Address = " + helloEventArgs.Endpoint.Address.AbsoluteUri); Debug.Print("Types:"); for (int t = 0; t < helloEventArgs.ServiceTypes.Count; ++t) { DpwsServiceType serviceType = helloEventArgs.ServiceTypes[t]; Debug.Print("\tName = " + serviceType.TypeName); Debug.Print("\tNamespace = " + serviceType.NamespaceUri); Debug.Print(""); } Debug.Print("XAddrs:"); foreach (string xaddr in helloEventArgs.XAddrs) { Debug.Print("\tTransport Address = " + xaddr); } Debug.Print("Metadata Version = " + helloEventArgs.MetadataVersion); }
/// <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); }
// 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); } }
public MFTestResults ClientTest_DpwsServiceType() { /// <summary> /// 1. Verifies each of the proerties of a DpwsServiceType object /// </summary> /// bool testResult = true; try { String typeName = "typeName"; String namespaceUri = "namespaceUri"; DpwsServiceType testDST = new DpwsServiceType(typeName, namespaceUri); Log.Comment("NamespaceUri"); if (testDST.NamespaceUri != null) { if (testDST.NamespaceUri.GetType() != Type.GetType("System.String")) { throw new Exception("NamespaceUri wrong type"); } } if (testDST.NamespaceUri != namespaceUri) { throw new Exception("NamespaceUri bad data"); } Log.Comment("TypeName"); if (testDST.TypeName != null) { if (testDST.TypeName.GetType() != Type.GetType("System.String")) { throw new Exception("TypeName wrong type"); } } if (testDST.TypeName != typeName) { throw new Exception("TypeName bad data"); } } catch (Exception e) { testResult = false; Log.Comment("Incorrect exception caught: " + e.Message); } return(testResult ? MFTestResults.Pass : MFTestResults.Fail); }
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."); } }
/// <summary> /// Creates an instance a DpwsSubscribeRequest class initialized with the service endpoint Address, /// notifyTo callback endpoint address and event duration. /// </summary> /// <param name="subscriptionType">A DpwsServieType object containing a definition of the service being subscripbed to.</param> /// <param name="endpointAddress">A string containing an event source endpoint address.</param> /// <param name="notifyToAddress">A string containing the notifyTo endpoint address.</param> /// <param name="expires"> /// A string containing the subscription expiration time in duration format. If /// null the event does not expire. /// </param> /// <param name="identifier">A WsWsaRefParamter object containing a unique identifier. /// This value will be included in an event messages soap header as a reference parameter. /// This value is not processed by a service it is intended to provide a unique identified /// a client can use for any purpose.</param> /// <remarks> /// This constructor sets the endTo address to null indicating that the notifyTo address should receive /// subscription end messages. A user ID for the event is not set by default. /// </remarks> /// <exception cref="ArgumentException">If duration format is invalid.</exception> public DpwsSubscribeRequest(DpwsServiceType subscriptionType, string endpointAddress, string notifyToAddress, string expires, WsXmlNode identifier) { if (endpointAddress == null || notifyToAddress == null) throw new ArgumentNullException(); this.SubscriptionType = subscriptionType; this.EndpointAddress = new Uri(endpointAddress); this.NotifyTo = new WsWsaEndpointRef(new Uri(notifyToAddress)); this.EndTo = new WsWsaEndpointRef(new Uri(notifyToAddress)); if (identifier != null) { this.NotifyTo.RefProperties.Add(identifier); this.EndTo.RefProperties.Add(identifier); } if (expires != null) this.Expires = new WsDuration(expires); }
public void PrintResolveMatchInfo() { Debug.Print("Resolving a device..."); string endpointAddr = "urn:uuid:c5201073-fa27-c8c9-9634-0000001dd159"; DpwsServiceDescription resolveMatch = this.DiscoveryClient.Resolve(endpointAddr); if (resolveMatch != null) { // Print resolve match information Debug.Print(""); Debug.Print("Resolve Match:"); Debug.Print("Endpoint Address = " + resolveMatch.Endpoint.Address.AbsoluteUri); Debug.Print("Types:"); for (int t = 0; t < resolveMatch.ServiceTypes.Count; ++t) { DpwsServiceType matchType = resolveMatch.ServiceTypes[t]; Debug.Print("\tName = " + matchType.TypeName); Debug.Print("\tNamespace = " + matchType.NamespaceUri); Debug.Print(""); } Debug.Print("XAddrs:"); foreach (string xaddr in resolveMatch.XAddrs) { Debug.Print("\tTransport Address = " + xaddr); } Debug.Print("Metadata Version = " + resolveMatch.MetadataVersion); } else { Debug.Print("Device cannot be resolved."); } }
public void PrintMetadataInfo() { this.IgnoreRequestFromThisIP = true; // This is the endpoint (logical) address of the target device // we want to obtain the metadata string deviceEndpointAddr = "urn:uuid:bde0943a-0516-c8ca-80a6-000000b525ed"; Debug.Print("Resolving the device..."); // We need to resolve the device to get the transport address DpwsServiceDescription resolveMatch = this.DiscoveryClient.Resolve(deviceEndpointAddr); if (resolveMatch != null) { // Device was located string deviceTransportAddr = resolveMatch.XAddrs[0]; // Get metadata DpwsMexClient mexClient = new DpwsMexClient(); DpwsMetadata metadata = mexClient.Get(deviceTransportAddr); if (metadata != null) { Debug.Print(""); Debug.Print("Metadata:"); Debug.Print("ThisModel:"); Debug.Print("\tManufacturer: " + metadata.ThisModel.Manufacturer); Debug.Print("\tManufacturerUrl: " + metadata.ThisModel.ManufacturerUrl); Debug.Print("\tModelName: " + metadata.ThisModel.ModelName); Debug.Print("\tModelNumber: " + metadata.ThisModel.ModelNumber); Debug.Print("\tModelUrl: " + metadata.ThisModel.ModelUrl); Debug.Print("\tPresentationUrl: " + metadata.ThisModel.PresentationUrl); Debug.Print("ThisDevice:"); Debug.Print("\tFirmwareVersion: " + metadata.ThisDevice.FirmwareVersion); Debug.Print("\tFriendlyName: " + metadata.ThisDevice.FriendlyName); Debug.Print("\tSerialNumber: " + metadata.ThisDevice.SerialNumber); DpwsMexService host = metadata.Relationship.Host; if (host != null) { Debug.Print("Host:"); Debug.Print("\tServiceID: " + host.ServiceID); Debug.Print("\tAddress: " + host.EndpointRefs[0].Address.AbsoluteUri); Debug.Print("\tTypes:"); for (int t = 0; t < host.ServiceTypes.Count; ++t) { DpwsServiceType serviceType = host.ServiceTypes[t]; Debug.Print("\t\tName = " + serviceType.TypeName); Debug.Print("\t\tNamespace = " + serviceType.NamespaceUri); Debug.Print(""); } } DpwsMexServices hostedServices = metadata.Relationship.HostedServices; if (hostedServices != null) { Debug.Print("HostedServices:"); for (int i = 0; i < hostedServices.Count; i++) { DpwsMexService hostedService = hostedServices[i]; Debug.Print("\tService ID: " + hostedService.ServiceID); Debug.Print("\tAddress: " + hostedService.EndpointRefs[0].Address.AbsoluteUri); Debug.Print("\tTypes:"); for (int t = 0; t < hostedService.ServiceTypes.Count; ++t) { DpwsServiceType serviceType = hostedService.ServiceTypes[t]; Debug.Print("\t\tName = " + serviceType.TypeName); Debug.Print("\t\tNamespace = " + serviceType.NamespaceUri); Debug.Print(""); } } } } else { Debug.Print("Did not get metadata from device."); } } else { Debug.Print("Device cannot be resolved."); } }
/// <summary> /// Builds a probe request message based on the filters parameter. /// </summary> /// <param name="serviceAddress"> /// A string containing the target service address. /// For example: urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b20 /// </param> /// <param name="filters"> /// A DpwsServiceTypes object containing a collection of types a service must support to signal a match. /// Null = any type. /// </param> /// <param name="messageID"> /// A string used to return the messageID assigned to this message. /// </param> /// <returns>A byte array containing the probe message or null if an error occures.</returns> private WsMessage BuildProbeRequest(string serviceAddress, DpwsServiceTypes filters, out String messageID) { // Performance debugging DebugTiming timeDebuger = new DebugTiming(); long startTime = timeDebuger.ResetStartTime(""); WsMessage msg = null; // Build Probe request using (XmlMemoryWriter xmlWriter = XmlMemoryWriter.Create()) { WsWsaHeader header = new WsWsaHeader( m_version.DiscoveryNamespace + "/Probe", // Action null, // RelatesTo serviceAddress, // To (m_version is ProtocolVersion11? m_version.AnonymousUri : null), null, null); // ReplyTo, From, Any header.MustUnderstand = true; // If filters are supplied, write filter namespaces if prefixed. Build filter list for use later WsXmlNamespaces namespaces = new WsXmlNamespaces(); // Prefix hack for now: int i = 0; string prefix; string filterList = ""; bool spaceFlag = false; if (filters != null) { int count = filters.Count; for (int j = 0; j < count; j++) { DpwsServiceType serviceType = filters[j]; prefix = namespaces.LookupPrefix(serviceType.NamespaceUri); if (prefix == null) { prefix = "dp" + (i++); namespaces.Add(new WsXmlNamespace(prefix, serviceType.NamespaceUri)); } filterList = filterList + ((spaceFlag == true) ? " " : "") + prefix + ":" + serviceType.TypeName; spaceFlag = true; } } msg = new WsMessage(header, null, WsPrefix.Wsd, namespaces, null); WsSoapMessageWriter smw = new WsSoapMessageWriter(m_version); messageID = smw.WriteSoapMessageStart(xmlWriter, msg); // Performance debuging timeDebuger.PrintElapsedTime("*****Write Header Took"); // write body xmlWriter.WriteStartElement(WsNamespacePrefix.Wsd, "Probe", null); // If filter is supplied add filter types tag else write blank string to probe body, force an empty tag if (filterList.Length != 0) { xmlWriter.WriteStartElement(WsNamespacePrefix.Wsd, "Types", null); xmlWriter.WriteString(filterList); xmlWriter.WriteEndElement(); // End Filter } else { xmlWriter.WriteString(""); } xmlWriter.WriteEndElement(); // End Probe // Performance debuging timeDebuger.PrintElapsedTime("*****Write Body Took"); smw.WriteSoapMessageEnd(xmlWriter); // Performance debuging timeDebuger.PrintTotalTime(startTime, "***Probe Message Build Took"); // return the probe message msg.Body = xmlWriter.ToArray(); } return(msg); }
/// <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("SimpleDeviceType", "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); }
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(); } }
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); }
public void PrintMetadataInfo() { // This is the endpoint (logical) address of the target device // we want to obtain the metadata (keep in sync with SimpleService project) string deviceEndpointAddr = "urn:uuid:18571766-87df-06e2-bb68-5136c48f483a"; Debug.Print("Resolving the device..."); // We need to resolve the device to get the transport address DpwsServiceDescription resolveMatch = m_simpleServiceClient.DiscoveryClient.Resolve(deviceEndpointAddr); //if(true) if (resolveMatch != null) { // Device was located string deviceTransportAddr = resolveMatch.XAddrs[0]; // If transport address ends with '/' remove it int length = deviceTransportAddr.Length; if (deviceTransportAddr[length - 1] == '/') { deviceTransportAddr = deviceTransportAddr.Substring(0, length - 1); } // Get metadata DpwsMexClient mexClient = new DpwsMexClient(new ProtocolVersion10()); DpwsMetadata metadata = mexClient.Get(deviceTransportAddr); if (metadata != null) { Debug.Print(""); Debug.Print("Metadata:"); Debug.Print("ThisModel:"); Debug.Print("\tManufacturer: " + metadata.ThisModel.Manufacturer); Debug.Print("\tManufacturerUrl: " + metadata.ThisModel.ManufacturerUrl); Debug.Print("\tModelName: " + metadata.ThisModel.ModelName); Debug.Print("\tModelNumber: " + metadata.ThisModel.ModelNumber); Debug.Print("\tModelUrl: " + metadata.ThisModel.ModelUrl); Debug.Print("\tPresentationUrl: " + metadata.ThisModel.PresentationUrl); Debug.Print("ThisDevice:"); Debug.Print("\tFirmwareVersion: " + metadata.ThisDevice.FirmwareVersion); Debug.Print("\tFriendlyName: " + metadata.ThisDevice.FriendlyName); Debug.Print("\tSerialNumber: " + metadata.ThisDevice.SerialNumber); DpwsMexService host = metadata.Relationship.Host; if (host != null) { Debug.Print("Host:"); Debug.Print("\tServiceID: " + host.ServiceID); Debug.Print("\tAddress: " + host.EndpointRefs[0].Address.AbsoluteUri); Debug.Print("\tTypes:"); for (int t = 0; t < host.ServiceTypes.Count; ++t) { DpwsServiceType serviceType = host.ServiceTypes[t]; Debug.Print("\t\tName = " + serviceType.TypeName); Debug.Print("\t\tNamespace = " + serviceType.NamespaceUri); Debug.Print(""); } } DpwsMexServices hostedServices = metadata.Relationship.HostedServices; if (hostedServices != null) { Debug.Print("HostedServices:"); for (int i = 0; i < hostedServices.Count; i++) { DpwsMexService hostedService = hostedServices[i]; Debug.Print("\tService ID: " + hostedService.ServiceID); Debug.Print("\tAddress: " + hostedService.EndpointRefs[0].Address.AbsoluteUri); Debug.Print("\tTypes:"); for (int t = 0; t < hostedService.ServiceTypes.Count; ++t) { DpwsServiceType serviceType = hostedService.ServiceTypes[t]; Debug.Print("\t\tName = " + serviceType.TypeName); Debug.Print("\t\tNamespace = " + serviceType.NamespaceUri); Debug.Print(""); } } } } else { Debug.Print("Did not get metadata from device."); } } else { Debug.Print("Device cannot be resolved."); } }
/// <summary> /// Builds a probe request message based on the filters parameter. /// </summary> /// <param name="serviceAddress"> /// A string containing the target service address. /// For example: urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b20 /// </param> /// <param name="filters"> /// A DpwsServiceTypes object containing a collection of types a service must support to signal a match. /// Null = any type. /// </param> /// <param name="messageID"> /// A string used to return the messageID assigned to this message. /// </param> /// <returns>A byte array containing the probe message or null if an error occures.</returns> private byte[] BuildProbeRequest(string serviceAddress, DpwsServiceTypes filters, out String messageID) { // Performance debugging DebugTiming timeDebuger = new DebugTiming(); long startTime = timeDebuger.ResetStartTime(""); // Build Probe request MemoryStream soapStream = new MemoryStream(); XmlWriter xmlWriter = XmlWriter.Create(soapStream); WsWsaHeader header = new WsWsaHeader( WsWellKnownUri.WsdNamespaceUri + "/Probe", // Action null, // RelatesTo serviceAddress, // To null, null, null); // ReplyTo, From, Any // If filters are supplied, write filter namespaces if prefixed. Build filter list for use later, // include wsdp:device. WsXmlNamespaces namespaces = new WsXmlNamespaces(); // Prefix hack for now: int i = 0; string prefix; string filterList = ""; bool spaceFlag = false; if (filters != null) { int count = filters.Count; for (int j = 0; j < count; j++) { DpwsServiceType serviceType = filters[j]; prefix = namespaces.LookupPrefix(serviceType.NamespaceUri); if (prefix == null) { prefix = "MyPrefix" + (i++); namespaces.Add(new WsXmlNamespace(prefix, serviceType.NamespaceUri)); } filterList = filterList + ((spaceFlag == true) ? " " : "") + prefix + ":" + serviceType.TypeName; spaceFlag = true; } } messageID = WsSoapMessageWriter.WriteSoapMessageStart(xmlWriter, WsSoapMessageWriter.Prefixes.Wsd, namespaces, header, null); // Performance debuging timeDebuger.PrintElapsedTime("*****Write Header Took"); // write body xmlWriter.WriteStartElement("wsd", "Probe", null); // If filter is supplied add filter types tag else write blank string to probe body, force an empty tag if (filterList.Length != 0) { xmlWriter.WriteStartElement("wsd", "Types", null); xmlWriter.WriteString(filterList); xmlWriter.WriteEndElement(); // End Filter } else { xmlWriter.WriteString(""); } xmlWriter.WriteEndElement(); // End Probe // Performance debuging timeDebuger.PrintElapsedTime("*****Write Body Took"); WsSoapMessageWriter.WriteSoapMessageEnd(xmlWriter); // Performance debuging timeDebuger.PrintTotalTime(startTime, "***Probe Message Build Took"); // Flush and close writer xmlWriter.Flush(); xmlWriter.Close(); // return the probe message return(soapStream.ToArray()); }