public MFTestResults WsaAddressingtest_WsWsaEndpointRefs() { /// <summary> /// 1. Verifies the properties of a WsWsaEndpointRefs object /// 2. Adds elements to it /// 3. Re-verifies /// 4. Empties the object /// 5. Re-verifies /// </summary> /// bool testResult = true; try { WsWsaEndpointRefs testWWERs = new WsWsaEndpointRefs(); if (testWWERs.Count != 0) { throw new Exception("Count did not set correctly on new"); } testWWERs.Add(new WsWsaEndpointRef(new System.Uri(WsWellKnownUri.SchemaNamespaceUri))); testWWERs.Add(new WsWsaEndpointRef(new System.Uri(WsWellKnownUri.SoapNamespaceUri))); if (testWWERs.Count != 2) { throw new Exception("Count did not set correctly on new"); } testWWERs.Clear(); if (testWWERs.Count != 0) { throw new Exception("After removing count is not back to zero"); } testWWERs.Add(new WsWsaEndpointRef(new System.Uri(WsWellKnownUri.SchemaNamespaceUri))); WsWsaEndpointRef ep = new WsWsaEndpointRef(new System.Uri(WsWellKnownUri.SoapNamespaceUri)); testWWERs.Add(ep); testWWERs.Remove(ep); if (testWWERs.Count != 1) { throw new Exception("Remove did not correctly remove the item"); } } catch (Exception e) { testResult = false; Log.Comment("Incorrect exception caught: " + e.Message); } return(testResult ? MFTestResults.Pass : MFTestResults.Fail); }
/// <summary> /// Method used to write an endpoint reference and reference parameters or properties. /// </summary> /// <param name="xmlWriter">An XmlWriter used to write the endpoint reference.</param> /// <param name="endpointRef">A WsWsaEndpointRef containing the information to write.</param> private void WriteEndpointRef(XmlWriter xmlWriter, WsWsaEndpointRef endpointRef, String name) { xmlWriter.WriteStartElement(WsNamespacePrefix.Wse, name, null); xmlWriter.WriteStartElement(WsNamespacePrefix.Wsa, "Address", null); xmlWriter.WriteString(endpointRef.Address.AbsoluteUri); xmlWriter.WriteEndElement(); // End Address // if ref paramters write them if (endpointRef.RefParameters != null && endpointRef.RefParameters.Count > 0) { xmlWriter.WriteStartElement(WsNamespacePrefix.Wsa, "ReferenceParameters", null); // Iterate ref parameters int count = endpointRef.RefParameters.Count; for (int i = 0; i < count; i++) { WsXmlNode refParam = endpointRef.RefParameters[i]; // Write the element name xmlWriter.WriteStartElement(refParam.Prefix, refParam.LocalName, refParam.NamespaceURI); // Write the value xmlWriter.WriteString(refParam.Value); xmlWriter.WriteEndElement(); // End param element } xmlWriter.WriteEndElement(); // End ReferenceParameters } // if ref properties write them if (endpointRef.RefProperties != null && endpointRef.RefProperties.Count > 0) { xmlWriter.WriteStartElement(WsNamespacePrefix.Wsa, "ReferenceProperties", null); // Iterate ref parameters int count = endpointRef.RefProperties.Count; for (int i = 0; i < count; i++) { WsXmlNode refProp = endpointRef.RefProperties[i]; // Write the element name xmlWriter.WriteStartElement(refProp.Prefix, refProp.LocalName, refProp.NamespaceURI); // Write the value xmlWriter.WriteString(refProp.Value); xmlWriter.WriteEndElement(); // End property element } xmlWriter.WriteEndElement(); // End ReferenceProperties } xmlWriter.WriteEndElement(); // End EndpointReference return; }
/// <summary> /// Create an instance of a SubscriptionEndEvent arguments object. /// </summary> internal SubscriptionEndEventArgs(WsWsaHeader header, XmlReader reader) { // Retrieve the Identifier this.Identifier = header.Any.GetNodeValue("Identifier", WsWellKnownUri.WseNamespaceUri); reader.ReadStartElement("SubscriptionEnd", WsWellKnownUri.WseNamespaceUri); if (reader.IsStartElement("SubscriptionManager", WsWellKnownUri.WseNamespaceUri)) { this.SubscriptionManager = new WsWsaEndpointRef(reader); } this.SubscriptionID = this.SubscriptionManager.RefParameters.GetNodeValue("Identifier", WsWellKnownUri.WseNamespaceUri); if (this.SubscriptionID == null || this.Identifier == null) // both need to be there { throw new XmlException(); } }
/// <summary> /// Create an instance of a SubscriptionEndEvent arguments object. /// </summary> internal SubscriptionEndEventArgs(WsMessage msg, ProtocolVersion version) { // Retrieve the Identifier WsWsaHeader header = msg.Header; XmlReader reader = msg.Reader; this.Identifier = header.Any.GetNodeValue("Identifier", version.EventingNamespace); reader.ReadStartElement("SubscriptionEnd", version.EventingNamespace); if (reader.IsStartElement("SubscriptionManager", version.EventingNamespace)) { this.SubscriptionManager = new WsWsaEndpointRef(reader, version.AddressingNamespace); } this.SubscriptionID = this.SubscriptionManager.RefParameters.GetNodeValue("Identifier", version.EventingNamespace); if (this.SubscriptionID == null || this.Identifier == null) // both need to be there { throw new XmlException(); } }
/// <summary> /// Creates an instance of a DpwsServiceDescription class initialized with a service endpoint and a list of /// supported service types. /// </summary> /// <param name="endpoint">A WsWsaEndpointRef object containing a Dpws Device servie endpoint.</param> /// <param name="serviceTypes">A string array containing a list of service types supporte by a Dpws devie service endpoint.</param> public DpwsServiceDescription(WsWsaEndpointRef endpoint, DpwsServiceTypes serviceTypes) { this.Endpoint = endpoint; this.ServiceTypes = serviceTypes; }
public virtual WsMessage ResolveMatch(WsMessage message) { XmlReader reader = message.Reader; WsWsaHeader header = message.Header; bool match = false; string epAddr = ""; reader.ReadStartElement("Resolve", this.Version.DiscoveryNamespace); if (reader.IsStartElement("EndpointReference", this.Version.AddressingNamespace) == false) { return(null); } WsWsaEndpointRef epRef = new WsWsaEndpointRef(reader, this.Version.AddressingNamespace); epAddr = epRef.Address.AbsoluteUri; if (Device.EndpointAddress != epAddr) { // If the destination endpoint is ours send a resolve match else return null int servicesCount = Device.HostedServices.Count; DpwsHostedService hostedService; for (int i = 0; i < servicesCount; i++) { hostedService = (DpwsHostedService)Device.HostedServices[i]; // Skip internal services if (hostedService.ServiceTypeName == "Internal") { continue; } if (hostedService.EndpointAddress == epAddr) { match = true; break; } } if (!match) { return(null); } } // Build ResolveMatch 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 + "/ResolveMatches", // 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); // write body xmlWriter.WriteStartElement(WsNamespacePrefix.Wsd, "ResolveMatches", null); xmlWriter.WriteStartElement(WsNamespacePrefix.Wsd, "ResolveMatch", null); xmlWriter.WriteStartElement(WsNamespacePrefix.Wsa, "EndpointReference", null); xmlWriter.WriteStartElement(WsNamespacePrefix.Wsa, "Address", null); xmlWriter.WriteString(epRef.Address.AbsoluteUri); xmlWriter.WriteEndElement(); // End Address xmlWriter.WriteEndElement(); // End EndpointReference // Write hosted service types xmlWriter.WriteStartElement(WsNamespacePrefix.Wsd, "Types", null); WriteDeviceServiceTypes(xmlWriter); xmlWriter.WriteEndElement(); // End Types string transport = Device.TransportAddress; if (match) { int idx = transport.LastIndexOf('/'); if (idx != -1) { transport = transport.Substring(0, idx + 1); transport += epAddr.Substring(epAddr.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.WriteStartElement(WsNamespacePrefix.Wsd, "XAddrs", null); xmlWriter.WriteString(transport); xmlWriter.WriteEndElement(); // End XAddrs xmlWriter.WriteStartElement(WsNamespacePrefix.Wsd, "MetadataVersion", null); xmlWriter.WriteString(Device.MetadataVersion.ToString()); xmlWriter.WriteEndElement(); // End MetadataVersion xmlWriter.WriteEndElement(); // End ResolveMatch xmlWriter.WriteEndElement(); // End ResolveMatches smw.WriteSoapMessageEnd(xmlWriter); msg.Body = xmlWriter.ToArray(); // Return stream buffer return(msg); } }
public MFTestResults WsaAddressingtest_WsWsaEndpointRef() { /// <summary> /// 1. Gets and verifies each of the properties of a WsWsaEndpointRef object /// 2. Sets and re-verifies all properties /// </summary> /// bool testResult = true; try { WsWsaEndpointRef testWWER = new WsWsaEndpointRef(new System.Uri(WsWellKnownUri.SoapNamespaceUri)); Log.Comment("Address"); if (testWWER.Address != null) { if (testWWER.Address.GetType() != Type.GetType("System.Uri")) { throw new Exception("Address wrong type"); } } if (testWWER.Address.AbsoluteUri != new System.Uri(WsWellKnownUri.SoapNamespaceUri).AbsoluteUri) { throw new Exception("Address wrong data"); } Log.Comment("RefProperties"); if (testWWER.RefProperties != null) { if (testWWER.RefProperties.GetType() != Type.GetType("Ws.Services.Xml.WsXmlNodeList")) { throw new Exception("RefProperties wrong type"); } } if (testWWER.RefProperties.ToString() != new Ws.Services.Xml.WsXmlNodeList().ToString()) { throw new Exception("RefProperties wrong data"); } Log.Comment("RefParameters"); if (testWWER.RefParameters != null) { if (testWWER.RefParameters.GetType() != Type.GetType("Ws.Services.Xml.WsXmlNodeList")) { throw new Exception("RefParameters wrong type"); } } if (testWWER.RefParameters.ToString() != new Ws.Services.Xml.WsXmlNodeList().ToString()) { throw new Exception("RefParameters wrong data"); } } catch (Exception e) { testResult = false; Log.Comment("Incorrect exception caught: " + e.Message); } return(testResult ? MFTestResults.Pass : MFTestResults.Fail); }
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); }
public virtual byte[] ResolveMatch(WsWsaHeader header, XmlReader reader) { reader.ReadStartElement("Resolve", WsWellKnownUri.WsdNamespaceUri); if (reader.IsStartElement("EndpointReference", WsWellKnownUri.WsaNamespaceUri_2005_08) == false) { return(null); } WsWsaEndpointRef epRef = new WsWsaEndpointRef(reader); // If the destination endpoint is ours send a resolve match else return null if (Device.EndpointAddress != epRef.Address.AbsoluteUri) { return(null); } // Build ResolveMatch MemoryStream soapStream = new MemoryStream(); XmlWriter xmlWriter = XmlWriter.Create(soapStream); // 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( WsWellKnownUri.WsdNamespaceUri + "/ResolveMatches", // Action header.MessageID, // RelatesTo WsWellKnownUri.WsaAnonymousUri, // To null, null, null); // ReplyTo, From, Any WsSoapMessageWriter.WriteSoapMessageStart(xmlWriter, WsSoapMessageWriter.Prefixes.Wsd | WsSoapMessageWriter.Prefixes.Wsdp, // Prefix additionalPrefixes, // Additional Prefixes matchHeader, // Header new WsSoapMessageWriter.AppSequence(Device.AppSequence, Device.SequenceID, Device.MessageID)); // AppSequence // write body xmlWriter.WriteStartElement("wsd", "ResolveMatches", WsWellKnownUri.WsdNamespaceUri); xmlWriter.WriteStartElement("wsd", "ResolveMatch", WsWellKnownUri.WsdNamespaceUri); xmlWriter.WriteStartElement("wsa", "EndpointReference", WsWellKnownUri.WsaNamespaceUri_2005_08); xmlWriter.WriteStartElement("wsa", "Address", WsWellKnownUri.WsaNamespaceUri_2005_08); xmlWriter.WriteString(Device.EndpointAddress); xmlWriter.WriteEndElement(); // End Address xmlWriter.WriteEndElement(); // End EndpointReference // Write hosted service types xmlWriter.WriteStartElement("wsd", "Types", WsWellKnownUri.WsdNamespaceUri); WriteDeviceServiceTypes(xmlWriter); xmlWriter.WriteEndElement(); // End Types xmlWriter.WriteStartElement("wsd", "XAddrs", WsWellKnownUri.WsdNamespaceUri); xmlWriter.WriteString(Device.TransportAddress); xmlWriter.WriteEndElement(); // End XAddrs xmlWriter.WriteStartElement("wsd", "MetadataVersion", WsWellKnownUri.WsdNamespaceUri); xmlWriter.WriteString(Device.MetadataVersion.ToString()); xmlWriter.WriteEndElement(); // End MetadataVersion xmlWriter.WriteEndElement(); // End ResolveMatch xmlWriter.WriteEndElement(); // End ResolveMatches WsSoapMessageWriter.WriteSoapMessageEnd(xmlWriter); // Flush and close writer. Return stream buffer xmlWriter.Flush(); xmlWriter.Close(); return(soapStream.ToArray()); }