// Builds Service Types list. This hack is required because service spec writers determined that // more than one service type can live at a single endpoint address. Why you would want to break // the object model and allow this feature is unknown so for now we must hack. private string BuildServiceTypesList(DpwsHostedService service, ArrayList processedEndpointList) { if (processedEndpointList.Contains(service.EndpointAddress)) { return(null); } else { processedEndpointList.Add(service.EndpointAddress); } int serviceCount = Device.HostedServices.Count; string serviceTypes = null; for (int i = 0; i < serviceCount; ++i) { if (((DpwsHostedService)Device.HostedServices[i]).ServiceTypeName == "Internal") { continue; } if (service.EndpointAddress == Device.HostedServices[i].EndpointAddress) { serviceTypes = serviceTypes + ((serviceTypes == null) ? "" : " ") + ((DpwsHostedService)Device.HostedServices[i]).ServiceNamespace.Prefix + ":" + ((DpwsHostedService)Device.HostedServices[i]).ServiceTypeName; } } return(serviceTypes); }
public static void Main() { // *** Relationship (Services) *** // Set a simple service without any // operations and event as host service DpwsHostedService service1 = new DpwsHostedService(); service1.ServiceTypeName = "SimpleServiceType1"; service1.ServiceNamespace = new WsXmlNamespace("simple1", // prefix "http://schemas.sample.org/SimpleService1"); // namespace URI service1.ServiceID = "urn:uuid:cf16db78-02c9-c8ca-b37b-0000004071f6"; // Set the service as host service Device.Host = service1; // Add a second service as hosted service DpwsHostedService service2 = new DpwsHostedService(); service2.ServiceTypeName = "SimpleServiceType2"; service2.ServiceNamespace = new WsXmlNamespace("simple2", // prefix "http://schemas.sample.org/SimpleService2"); // namespace URI service2.ServiceID = "urn:uuid:ec499d62-02c9-c8ca-b7ee-0000000bf3dd"; // Add the service as hosted service Device.HostedServices.Add(service2); // Let clients identify this device Device.EndpointAddress = "urn:uuid:c5201073-fa27-c8c9-9634-0000001dd159"; // Set this device property if you want to ignore this clients request Device.IgnoreLocalClientRequest = false; // Start the device Device.Start(); // Keep the device alive Thread.Sleep(Timeout.Infinite); }
// Build an IntegerEvent private String BuildIntegerEventMessage(DpwsHostedService hostedService) { integerEventSerial++; return("<evnt:IntegerEvent xmlns:evnt='" + hostedService.ServiceNamespace.NamespaceURI + "'>" + "<evnt:Param>" + integerEventSerial + "</evnt:Param>" + "</evnt:IntegerEvent>"); }
public MFTestResults ServicesTest_DPWSHostedService_Methods() { /// <summary> /// This would test the methods in DPWSHostedService, but all of them are backend /// only methods. /// </summary> /// bool testResult = true; try { DpwsHostedService testDHS = Device.Host; //These methods are used only by the backend and are implicitly //tested by other tests //testDHS.GetStatus(new Ws.Services.WsaAddressing.WsWsaHeader(), // new Ws.Services.Xml.WsXmlDocument()); //testDHS.Renew(new Ws.Services.WsaAddressing.WsWsaHeader(), // new Ws.Services.Xml.WsXmlDocument()); //testDHS.Subscribe(new Ws.Services.WsaAddressing.WsWsaHeader(), // new Ws.Services.Xml.WsXmlDocument()); //testDHS.Unsubscribe(new Ws.Services.WsaAddressing.WsWsaHeader(), // new Ws.Services.Xml.WsXmlDocument()); } catch (Exception e) { testResult = false; Log.Comment("Incorrect exception caught: " + e.Message); } return(testResult ? MFTestResults.Pass : MFTestResults.Fail); }
// Write Service Types list. private void WriteDeviceServiceTypes(XmlWriter xmlWriter) { // Write the default p:Device type xmlWriter.WriteString(WsNamespacePrefix.Wsdp + ":Device"); // If device has a Host service add the Host service type if (Device.Host != null) { DpwsHostedService hostedService = Device.Host; // Add a space delimiter xmlWriter.WriteString(" "); string serviceType = (string)hostedService.ServiceNamespace.Prefix + ":" + hostedService.ServiceTypeName; xmlWriter.WriteString(serviceType); } }
public static void Main() { // *** Relationship (Services) *** // Set a simple service without any // operations and event as host service DpwsHostedService service1 = new DpwsHostedService(); service1.ServiceTypeName = "SimpleServiceType1"; service1.ServiceNamespace = new WsXmlNamespace("simple1", "http://schemas.sample.org/SimpleService1"); service1.ServiceID = "urn:uuid:cf16db78-02c9-c8ca-b37b-0000004071f6"; // set the service as host service Device.Host = service1; // // Add a second service as hosted service DpwsHostedService service2 = new DpwsHostedService(); service2.ServiceTypeName = "SimpleServiceType2"; service2.ServiceNamespace = new WsXmlNamespace("simple2", "http://schemas.sample.org/SimpleService2"); service2.ServiceID = "urn:uuid:ec499d62-02c9-c8ca-b7ee-0000000bf3dd"; // Add the service as hosted service Device.HostedServices.Add(service2); // Let clients identify this device Device.EndpointAddress = "urn:uuid:bde0943a-0516-c8ca-80a6-000000b525ed"; // Set this device property if you want to ignore this clients request Device.IgnoreLocalClientRequest = false; // Metadata // ThisModel Device.ThisModel.Manufacturer = "Apress, Inc."; Device.ThisModel.ManufacturerUrl = "http://www.apress.com"; Device.ThisModel.ModelName = "MetadataProvidingModel"; Device.ThisModel.ModelNumber = "12345"; Device.ThisModel.ModelUrl = "http://www.apress.com"; Device.ThisModel.PresentationUrl = "http://www.apress.com"; // ThisDevice Device.ThisDevice.FriendlyName = "Describing device that provides metadata"; Device.ThisDevice.FirmwareVersion = "demo"; Device.ThisDevice.SerialNumber = "12345678"; // Start the device Device.Start(); // Keep the device alive Thread.Sleep(Timeout.Infinite); }
// Write Service Types list. Optionally add hosted service to the list private static void WriteDeviceServiceTypes(XmlWriter xmlWriter, bool includeHostedServices) { // Write the default wsdp:Device type xmlWriter.WriteString("wsdp:Device"); // If device has a Host service add the Host service type if (Device.Host != null) { DpwsHostedService hostedService = Device.Host; // Add a space delimiter xmlWriter.WriteString(" "); string serviceType = (string)hostedService.ServiceNamespace.Prefix + ":" + hostedService.ServiceTypeName; xmlWriter.WriteString(serviceType); } // Add hosted service to list if required if (includeHostedServices) { WriteHostedServiceTypes(xmlWriter); } }
public EventSimulator(DpwsHostedService hostedService) { m_hostedService = hostedService; }
public virtual WsMessage ProbeMatch(WsMessage probe, DpwsHostedService matchedService) { XmlReader reader = probe.Reader; WsWsaHeader header = probe.Header; // Performance debugging DebugTiming timeDebuger = new DebugTiming(); long startTime = timeDebuger.ResetStartTime(""); // Build ProbeMatch using (XmlMemoryWriter xmlWriter = XmlMemoryWriter.Create()) { // If a Host exist write the Host namespace WsXmlNamespaces additionalPrefixes = null; if (Device.Host != null) { additionalPrefixes = new WsXmlNamespaces(); additionalPrefixes.Add(Device.Host.ServiceNamespace); } WsWsaHeader matchHeader = new WsWsaHeader( this.Version.DiscoveryNamespace + "/ProbeMatches", // Action header.MessageID, // RelatesTo this.Version.AnonymousUri, // To null, null, null); // ReplyTo, From, Any WsMessage msg = new WsMessage(matchHeader, null, WsPrefix.Wsd | WsPrefix.Wsdp, additionalPrefixes, new WsAppSequence(Device.AppSequence, Device.SequenceID, Device.MessageID)); WsSoapMessageWriter smw = new WsSoapMessageWriter(this.Version); smw.WriteSoapMessageStart(xmlWriter, msg); // Performance debuging timeDebuger.PrintElapsedTime("*****Write Header Took"); // write body xmlWriter.WriteStartElement(WsNamespacePrefix.Wsd, "ProbeMatches", null); xmlWriter.WriteStartElement(WsNamespacePrefix.Wsd, "ProbeMatch", null); xmlWriter.WriteStartElement(WsNamespacePrefix.Wsa, "EndpointReference", null); xmlWriter.WriteStartElement(WsNamespacePrefix.Wsa, "Address", null); xmlWriter.WriteString(matchedService == null ? Device.EndpointAddress : matchedService.EndpointAddress); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); // Write hosted service types xmlWriter.WriteStartElement(WsNamespacePrefix.Wsd, "Types", null); WriteDeviceServiceTypes(xmlWriter); xmlWriter.WriteEndElement(); // End Types xmlWriter.WriteStartElement(WsNamespacePrefix.Wsd, "XAddrs", null); string transport = Device.TransportAddress; if (matchedService != null) { int idx = transport.LastIndexOf('/'); if (idx != -1) { transport = transport.Substring(0, idx + 1); transport += matchedService.EndpointAddress.Substring(matchedService.EndpointAddress.IndexOf("urn:uuid:") + 9); } } int idx2 = transport.ToLower().IndexOf("localhost"); if (idx2 != -1) { transport = transport.Substring(0, idx2) + WsNetworkServices.GetLocalIPV4Address() + transport.Substring(idx2 + 9 /*localhost*/); } xmlWriter.WriteString(transport); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement(WsNamespacePrefix.Wsd, "MetadataVersion", null); xmlWriter.WriteString(Device.MetadataVersion.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); smw.WriteSoapMessageEnd(xmlWriter); msg.Body = xmlWriter.ToArray(); // Performance debuging timeDebuger.PrintTotalTime(startTime, "***ProbeMatch Took"); // Delay probe match as per Ws-Discovery specification (2.4 Protocol Assignments) Thread.Sleep(new Random().Next(Device.ProbeMatchDelay)); // Return stream buffer return(msg); } }
// ProbeMatch response stub public WsMessage Probe(WsMessage msg) { // If Adhoc disco is turned off return null. Adhoc disco is optional with a Discovery Proxy if (Device.SupressAdhoc == true) { return(null); } XmlReader reader = msg.Reader; WsWsaHeader header = msg.Header; DpwsHostedService matchedService = null; string wsdNamespace = m_discovery.Version.DiscoveryNamespace; reader.ReadStartElement("Probe", wsdNamespace); bool match = true; bool fMatchAny = false; if (reader.IsStartElement("Types", wsdNamespace)) { // use MoveToContent, ReadString, Read instead of ReadElementString because local namespaces are popped // from the stack on return. reader.MoveToContent(); // Look for specified type, send probe match if any instance of any of the listed types are found string[] typesList = reader.ReadString().Trim().Split(' '); int count = typesList.Length; match = false; if (count == 0 || ((count == 1) && (typesList[0] == ""))) { fMatchAny = true; } if (count > 0 && !fMatchAny) { for (int i = 0; i < count; i++) { string type = typesList[i]; // Parse type string namespaceUri, prefix, typeName; int namespaceIndex = type.IndexOf(':'); if (namespaceIndex == -1) { namespaceUri = ""; typeName = type; } else { if (namespaceIndex == type.Length - 1) { throw new XmlException(); } prefix = type.Substring(0, namespaceIndex); namespaceUri = reader.LookupNamespace(prefix); if (namespaceUri == null) { namespaceUri = prefix; } typeName = type.Substring(namespaceIndex + 1); } // Check for the dpws standard type if (namespaceUri == m_version.WsdpNamespaceUri && typeName == "Device") { match = true; break; } // If there is a host check it if (Device.Host != null) { if (Device.Host.ServiceNamespace.NamespaceURI == namespaceUri && Device.Host.ServiceTypeName == typeName) { match = true; break; } } // Check for matching service int servicesCount = Device.HostedServices.Count; DpwsHostedService hostedService; for (i = 0; i < servicesCount; i++) { hostedService = (DpwsHostedService)Device.HostedServices[i]; // Skip internal services if (hostedService.ServiceTypeName == "Internal") { continue; } if (hostedService.ServiceNamespace.NamespaceURI == namespaceUri && hostedService.ServiceTypeName == typeName) { match = true; matchedService = hostedService; break; } } if (match) { break; } } } reader.Read(); // read the EndElement or the empty StartElement } if (reader.IsStartElement("Scopes", wsdNamespace)) { reader.MoveToContent(); // Look for specified scope. We do not support scopes at this point, so // any scope will result in no matches // TODO: Add support for scopes? string[] scopeList = reader.ReadString().Trim().Split(' '); int count = scopeList.Length; if (count == 1 && scopeList[0] == "") { count = 0; } if (count > 0) { match = false; fMatchAny = false; } reader.Read(); // read the EndElement or the empty StartElement } // For completeness sake // We don't care about the rest... XmlReaderHelper.SkipAllSiblings(reader); reader.ReadEndElement(); // Probe if (match || fMatchAny) { return(m_discovery.ProbeMatch(msg, matchedService)); } return(null); }
public byte[] GetResponse(WsWsaHeader header, XmlReader reader) { // Build ProbeMatch MemoryStream soapStream = new MemoryStream(); XmlWriter xmlWriter = XmlWriter.Create(soapStream); // Write service type namespaces WsXmlNamespaces additionalPrefixes = new WsXmlNamespaces(); if (Device.Host != null) { additionalPrefixes = new WsXmlNamespaces(); additionalPrefixes.Add(Device.Host.ServiceNamespace); } WsServiceEndpoints hostedServices = Device.HostedServices; int count = hostedServices.Count; for (int i = 0; i < count; i++) { DpwsHostedService hostedService = (DpwsHostedService)hostedServices[i]; // Don't return Mex Service namespace if (hostedService.ServiceTypeName == "Internal") { continue; } additionalPrefixes.Add(hostedService.ServiceNamespace); } WsWsaHeader responseHeader = new WsWsaHeader( WsWellKnownUri.WstNamespaceUri + "/GetResponse", // Action header.MessageID, // RelatesTo header.ReplyTo.Address.AbsoluteUri, // To null, null, null); WsSoapMessageWriter.WriteSoapMessageStart(xmlWriter, WsSoapMessageWriter.Prefixes.Wsx | WsSoapMessageWriter.Prefixes.Wsdp, // Prefix additionalPrefixes, // Additional Prefix responseHeader, // Header new WsSoapMessageWriter.AppSequence(Device.AppSequence, Device.SequenceID, Device.MessageID)); // AppSequence // write body xmlWriter.WriteStartElement("wsx", "Metadata", WsWellKnownUri.WsxNamespaceUri); // Write ThisModel metadata section xmlWriter.WriteStartElement("wsx", "MetadataSection", WsWellKnownUri.WsxNamespaceUri); xmlWriter.WriteAttributeString("Dialect", "http://schemas.xmlsoap.org/ws/2006/02/devprof/ThisModel"); xmlWriter.WriteStartElement("wsdp", "ThisModel", WsWellKnownUri.WsdpNamespaceUri); if (Device.ThisModel.Manufacturer != null && Device.ThisModel.Manufacturer != "") { xmlWriter.WriteStartElement("wsdp", "Manufacturer", WsWellKnownUri.WsdpNamespaceUri); xmlWriter.WriteString(Device.ThisModel.Manufacturer); xmlWriter.WriteEndElement(); // End Manufacturer } if (Device.ThisModel.ManufacturerUrl != null && Device.ThisModel.ManufacturerUrl != "") { xmlWriter.WriteStartElement("wsdp", "ManufacturerUrl", WsWellKnownUri.WsdpNamespaceUri); xmlWriter.WriteString(Device.ThisModel.ManufacturerUrl); xmlWriter.WriteEndElement(); // End ManufacturerUrl } if (Device.ThisModel.ModelName != null && Device.ThisModel.ModelName != "") { xmlWriter.WriteStartElement("wsdp", "ModelName", WsWellKnownUri.WsdpNamespaceUri); xmlWriter.WriteString(Device.ThisModel.ModelName); xmlWriter.WriteEndElement(); // End ModelName } if (Device.ThisModel.ModelNumber != null && Device.ThisModel.ModelNumber != "") { xmlWriter.WriteStartElement("wsdp", "ModelNumber", WsWellKnownUri.WsdpNamespaceUri); xmlWriter.WriteString(Device.ThisModel.ModelNumber); xmlWriter.WriteEndElement(); // End ModelNumber } if (Device.ThisModel.ModelUrl != null && Device.ThisModel.ModelUrl != "") { xmlWriter.WriteStartElement("wsdp", "ModelUrl", WsWellKnownUri.WsdpNamespaceUri); xmlWriter.WriteString(Device.ThisModel.ModelUrl); xmlWriter.WriteEndElement(); // End ModelUrl } if (Device.ThisModel.PresentationUrl != null && Device.ThisModel.PresentationUrl != "") { xmlWriter.WriteStartElement("wsdp", "PresentationUrl", WsWellKnownUri.WsdpNamespaceUri); xmlWriter.WriteString(Device.ThisModel.PresentationUrl); xmlWriter.WriteEndElement(); // End PresentationUrl } if (Device.ThisModel.Any != null) { Device.ThisModel.Any.WriteTo(xmlWriter); } xmlWriter.WriteStartElement("wsdp", "ModelName", WsWellKnownUri.WsdpNamespaceUri); xmlWriter.WriteString(Device.ThisModel.ModelName); xmlWriter.WriteEndElement(); // End ModelName xmlWriter.WriteEndElement(); // End ThisModel xmlWriter.WriteEndElement(); // End MetadataSection // Write ThisDevice metadata section xmlWriter.WriteStartElement("wsx", "MetadataSection", WsWellKnownUri.WsxNamespaceUri); xmlWriter.WriteAttributeString("Dialect", "http://schemas.xmlsoap.org/ws/2006/02/devprof/ThisDevice"); xmlWriter.WriteStartElement("wsdp", "ThisDevice", WsWellKnownUri.WsdpNamespaceUri); if (Device.ThisDevice.FriendlyName != null && Device.ThisDevice.FriendlyName != "") { xmlWriter.WriteStartElement("wsdp", "FriendlyName", WsWellKnownUri.WsdpNamespaceUri); xmlWriter.WriteString(Device.ThisDevice.FriendlyName); xmlWriter.WriteEndElement(); // End FriendlyName } if (Device.ThisDevice.FirmwareVersion != null && Device.ThisDevice.FirmwareVersion != "") { xmlWriter.WriteStartElement("wsdp", "FirmwareVersion", WsWellKnownUri.WsdpNamespaceUri); xmlWriter.WriteString(Device.ThisDevice.FirmwareVersion); xmlWriter.WriteEndElement(); // End FirmwareVersion } if (Device.ThisDevice.SerialNumber != null && Device.ThisDevice.SerialNumber != "") { xmlWriter.WriteStartElement("wsdp", "SerialNumber", WsWellKnownUri.WsdpNamespaceUri); xmlWriter.WriteString(Device.ThisDevice.SerialNumber); xmlWriter.WriteEndElement(); // End SerialNumber } if (Device.ThisDevice.Any != null) { Device.ThisDevice.Any.WriteTo(xmlWriter); } xmlWriter.WriteEndElement(); // End ThisDevice xmlWriter.WriteEndElement(); // End MetadataSection // Write next MetadataSection xmlWriter.WriteStartElement("wsx", "MetadataSection", WsWellKnownUri.WsxNamespaceUri); xmlWriter.WriteAttributeString("Dialect", "http://schemas.xmlsoap.org/ws/2006/02/devprof/Relationship"); // Write Relationship Elements xmlWriter.WriteStartElement("wsdp", "Relationship", WsWellKnownUri.WsdpNamespaceUri); xmlWriter.WriteAttributeString("Type", "http://schemas.xmlsoap.org/ws/2006/02/devprof/host"); // List used to maintain service endpoints that have been processed. Because the DPWS spec allows // for multiple service types at a single endpoint address, we must make sure we only create // a relationship once for all of the types at a service endpoint. ArrayList processedEndpointList = new ArrayList(); // If a Host type exist add it if (Device.Host != null) { xmlWriter.WriteStartElement("wsdp", "Host", WsWellKnownUri.WsdpNamespaceUri); WsWsaEndpointRef endpointReference; endpointReference = (WsWsaEndpointRef)Device.Host.EndpointRefs[0]; xmlWriter.WriteStartElement("wsa", "EndpointReference", WsWellKnownUri.WsaNamespaceUri_2005_08); xmlWriter.WriteStartElement("wsa", "Address", WsWellKnownUri.WsaNamespaceUri_2005_08); xmlWriter.WriteString(endpointReference.Address.AbsoluteUri); xmlWriter.WriteEndElement(); // End Address xmlWriter.WriteEndElement(); // End EndpointReference // Build list of all service types that share this endpoint address /* * string serviceTypes = null; * if ((serviceTypes = BuildServiceTypesList(Device.Host, processedEndpointList)) == null) * serviceTypes = Device.Host.ServiceNamespace.Prefix + ":" + Device.Host.ServiceTypeName; * else * serviceTypes = serviceTypes + " " + Device.Host.ServiceNamespace.Prefix + ":" + Device.Host.ServiceTypeName; */ // Write service types xmlWriter.WriteStartElement("wsdp", "Types", WsWellKnownUri.WsdpNamespaceUri); xmlWriter.WriteString(Device.Host.ServiceNamespace.Prefix + ":" + Device.Host.ServiceTypeName); xmlWriter.WriteEndElement(); // End Types // Write Service ID xmlWriter.WriteStartElement("wsdp", "ServiceId", WsWellKnownUri.WsdpNamespaceUri); xmlWriter.WriteString(Device.Host.ServiceID); xmlWriter.WriteEndElement(); // End ServiceID xmlWriter.WriteEndElement(); // End Hosted // Update processed endpoint list processedEndpointList.Add(Device.Host.EndpointAddress); } // Add hosted services types int serviceCount = hostedServices.Count; DpwsHostedService currentService; for (int i = 0; i < serviceCount; i++) { currentService = (DpwsHostedService)hostedServices[i]; // Don't return Mex Service type if (currentService.ServiceTypeName == "Internal") { continue; } // Build list of all service types that share this endpoint address string serviceTypes = null; if ((serviceTypes = BuildServiceTypesList(currentService, processedEndpointList)) == null) { continue; } // Write hosted start element xmlWriter.WriteStartElement("wsdp", "Hosted", WsWellKnownUri.WsdpNamespaceUri); // Write n number of endpoint references int epRefCount = currentService.EndpointRefs.Count; for (int j = 0; j < epRefCount; j++) { xmlWriter.WriteStartElement("wsa", "EndpointReference", WsWellKnownUri.WsaNamespaceUri_2005_08); xmlWriter.WriteStartElement("wsa", "Address", WsWellKnownUri.WsaNamespaceUri_2005_08); xmlWriter.WriteString(currentService.EndpointRefs[j].Address.AbsoluteUri); xmlWriter.WriteEndElement(); // End Address xmlWriter.WriteEndElement(); // End EndpointReference } // Write service types xmlWriter.WriteStartElement("wsdp", "Types", WsWellKnownUri.WsdpNamespaceUri); xmlWriter.WriteString(currentService.ServiceNamespace.Prefix + ":" + currentService.ServiceTypeName); xmlWriter.WriteEndElement(); // End Types // Write Service ID xmlWriter.WriteStartElement("wsdp", "ServiceId", WsWellKnownUri.WsdpNamespaceUri); xmlWriter.WriteString(currentService.ServiceID); xmlWriter.WriteEndElement(); // End ServiceID xmlWriter.WriteEndElement(); // End Hosted // Update processed endpoint list processedEndpointList.Add(currentService.EndpointAddress); } xmlWriter.WriteEndElement(); // End Relastionship xmlWriter.WriteEndElement(); // End MetadataSection xmlWriter.WriteEndElement(); // End Metadata WsSoapMessageWriter.WriteSoapMessageEnd(xmlWriter); // Flush and close writer. Return stream buffer xmlWriter.Flush(); xmlWriter.Close(); return(soapStream.ToArray()); }
public MFTestResults DeviceTest_ThisDevice() { /// <summary> /// 1. Verifies that each of the properties of the Device.ThisModel object is the correct type /// 2. Sets settable properties /// 3. Verifies their type again, and their data for non-nullable properties /// </summary> /// Device.Initialize(new WS2007HttpBinding(new HttpTransportBindingConfig("urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51", 8084)), new ProtocolVersion10()); // Set device information //Device.EndpointAddress = "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51"; Device.ThisModel.Manufacturer = "Microsoft Corporation"; Device.ThisModel.ManufacturerUrl = "http://www.microsoft.com/"; Device.ThisModel.ModelName = "SimpleService Test Device"; Device.ThisModel.ModelNumber = "1.0"; Device.ThisModel.ModelUrl = "http://www.microsoft.com/"; Device.ThisModel.PresentationUrl = "http://www.microsoft.com/"; Device.ThisDevice.FriendlyName = "SimpleService"; Device.ThisDevice.FirmwareVersion = "alpha"; Device.ThisDevice.SerialNumber = "12345678"; bool testResult = true; try { WsServiceEndpoints testWSEs = Device.HostedServices; if (testWSEs.GetType() != Type.GetType("Ws.Services.WsServiceEndpoints")) { throw new Exception("HostedServices bad type"); } string testString = Device.IPV4Address; if (testString.GetType() != Type.GetType("System.String")) { throw new Exception("IPV4Address bad type"); } int testInt = Device.MetadataVersion; if (testInt.GetType() != Type.GetType("System.Int32")) { throw new Exception("MetadataVersion bad type"); } Device.MetadataVersion = -12; if (Device.MetadataVersion != -12) { throw new Exception("MetadataVersion did not set to invalid int value"); } Device.MetadataVersion = 2; if (Device.MetadataVersion != 2) { throw new Exception("MetadataVersion did not set to valid value"); } testInt = Device.ProbeMatchDelay; if (testInt.GetType() != Type.GetType("System.Int32")) { throw new Exception("ProbeMatchDelay bad type"); } Device.ProbeMatchDelay = 2; if (Device.ProbeMatchDelay != 2) { throw new Exception("ProbeMatchDelay did not set to valid value"); } DpwsHostedService testDHS = Device.Host; if (testDHS != null) { if (testDHS.GetType() != Type.GetType("Dpws.Device.Services.DpwsHostedService")) { throw new Exception("DpwsHostedService bad type"); } } Device.Host = new DpwsHostedService(new ProtocolVersion10()); testDHS = Device.Host; if (testDHS != null) { if (testDHS.GetType() != Type.GetType("Dpws.Device.Services.DpwsHostedService")) { throw new Exception("DpwsHostedService bad type after set to new"); } } DpwsWseSubscriptionMgr testDWSM = Device.SubscriptionManager; if (testDWSM != null) { if (testDWSM.GetType() != Type.GetType("Dpws.Device.Services.DpwsWseSubscriptionMgr")) { throw new Exception("DpwsWseSubscriptionMgr bad type"); } } // EndpointAddress will be defined by each event sink Device.SubscriptionManager = new DpwsWseSubscriptionMgr(new WS2007HttpBinding(), new ProtocolVersion10()); testDWSM = Device.SubscriptionManager; if (testDWSM != null) { if (testDWSM.GetType() != Type.GetType("Dpws.Device.Services.DpwsWseSubscriptionMgr")) { throw new Exception("DpwsWseSubscriptionMgr bad type after set to new"); } } } catch (Exception e) { testResult = false; Log.Comment("Incorrect exception caught: " + e.Message); } return(testResult ? MFTestResults.Pass : MFTestResults.Fail); }
// Build a SimpleEvent private String BuildSimpleEventMessage(DpwsHostedService hostedService) { return("<evnt:SimpleEvent xmlns:evnt='" + hostedService.ServiceNamespace.NamespaceURI + "'/>"); }
public MFTestResults ServicesTest_DPWSHostedService_Properties() { /// <summary> /// 1. Verifies each of the proerties of a DPWSHostedService object /// 2. Sets and re-verifies for simple properties, checks input checking /// on properties that currently support it. /// </summary> /// bool testResult = true; try { DpwsHostedService testDHS = Device.Host; Log.Comment("EndpointAddress"); if (testDHS.EndpointAddress != null) { if (testDHS.EndpointAddress.GetType() != Type.GetType("System.String")) { throw new Exception("EndpointAddress wrong type"); } } testDHS.EndpointAddress = "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51"; if (testDHS.EndpointAddress.GetType() != Type.GetType("System.String")) { throw new Exception("EndpointAddress wrong type after set"); } if (testDHS.EndpointAddress != "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51") { throw new Exception("EndpointAddress bad data"); } try { testDHS.EndpointAddress = "test1"; throw new Exception("EndpointAddress failed to prevent bad data input"); } catch (System.ArgumentException) { } Log.Comment("EndpointRefs"); if (testDHS.EndpointRefs != null) { if (testDHS.EndpointRefs.GetType() != Type.GetType("Ws.Services.WsaAddressing.WsWsaEndpointRefs")) { throw new Exception("EndpointRefs wrong type"); } } if (testDHS.EndpointRefs != null) { if (testDHS.EndpointRefs.GetType() != Type.GetType("Ws.Services.WsaAddressing.WsWsaEndpointRefs")) { throw new Exception("EndpointRefs wrong type after set to new"); } } Log.Comment("EventSources"); if (testDHS.EventSources.GetType() != Type.GetType("Dpws.Device.Services.DpwsWseEventSources")) { throw new Exception("EventSources wrong type"); } testDHS.EventSources = new DpwsWseEventSources(); if (testDHS.EventSources.GetType() != Type.GetType("Dpws.Device.Services.DpwsWseEventSources")) { throw new Exception("EventSources wrong type after set to new"); } Log.Comment("ServiceID"); if (testDHS.ServiceID != null) { if (testDHS.ServiceID.GetType() != Type.GetType("System.String")) { throw new Exception("ServiceID wrong type"); } } testDHS.ServiceID = "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51"; if (testDHS.ServiceID.GetType() != Type.GetType("System.String")) { throw new Exception("ServiceID wrong type after set"); } if (testDHS.ServiceID != "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51") { throw new Exception("ServiceID bad data"); } try { testDHS.ServiceID = "test2"; throw new Exception("ServiceID failed to prevent bad data input"); } catch (System.ArgumentException) { } Log.Comment("ServiceNamespace"); if (testDHS.ServiceNamespace != null) { if (testDHS.ServiceNamespace.GetType() != Type.GetType("Ws.Services.Xml.WsXmlNamespace")) { throw new Exception("ServiceNamespace wrong type"); } } Log.Comment("WsServiceOperations"); if (testDHS.ServiceOperations.GetType() != Type.GetType("Ws.Services.WsServiceOperations")) { throw new Exception("WsServiceOperations wrong type"); } Log.Comment("ServiceTypeName"); if (testDHS.ServiceTypeName.GetType() != Type.GetType("System.String")) { throw new Exception("ServiceTypeName wrong type"); } testDHS.ServiceTypeName = "test3"; if (testDHS.ServiceTypeName.GetType() != Type.GetType("System.String")) { throw new Exception("ServiceTypeName wrong type after set"); } if (testDHS.ServiceTypeName != "test3") { throw new Exception("ServiceTypeName wrong data"); } } catch (Exception e) { testResult = false; Log.Comment("Incorrect exception caught: " + e.Message); } return(testResult ? MFTestResults.Pass : MFTestResults.Fail); }