예제 #1
0
 /// <summary>
 /// Removes the first occurrence of a specific WsaEndpointRef object from the colleciton.
 /// </summary>
 /// <param name="endpointReference">
 /// The WsaEndpointRef object to remove from the collection. The value can be null.</param>
 public void Remove(WsWsaEndpointRef endpointReference)
 {
     lock (m_threadLock)
     {
         m_EndpointReferences.Remove(endpointReference);
     }
 }
예제 #2
0
 /// <summary>
 /// Adds a WsaEndpointRef object to the end of the collection.
 /// </summary>
 /// <param name="value">The WsaEndpointRef object to be added to the end of the collection.
 /// The value can be null.
 /// </param>
 /// <returns>The index at which the WsaEndpointRef object has been added.</returns>
 public int Add(WsWsaEndpointRef value)
 {
     lock (m_threadLock)
     {
         return(m_EndpointReferences.Add(value));
     }
 }
예제 #3
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);
        }
        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);
        }
예제 #5
0
        public WsWsaHeader(String action, String relatesTo, String to, String replyTo, String from, WsXmlNodeList any)
        {
            _action    = action;
            _relatesTo = relatesTo;
            _to        = to;
            if (replyTo != null)
            {
                _replyTo = new WsWsaEndpointRef(new System.Uri(replyTo));
            }

            if (from != null)
            {
                _from = new WsWsaEndpointRef(new System.Uri(from));
            }

            _any = any;
        }
예제 #6
0
        public WsWsaHeader(String action, String relatesTo, String to, String replyTo, String from, WsXmlNodeList any)
        {
            _action = action;
            _relatesTo = relatesTo;
            _to = to;
            if (replyTo != null)
            {
                _replyTo = new WsWsaEndpointRef(new System.Uri(replyTo));
            }

            if (from != null)
            {
                _from = new WsWsaEndpointRef(new System.Uri(from));
            }

            _any = any;
        }
예제 #7
0
        /// <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();
            }
        }
예제 #9
0
        internal void ParseHeader(XmlReader reader)
        {
            RequiredHeaderElement headerElements = RequiredHeaderElement.None;

            try
            {
                reader.ReadStartElement("Header", WsWellKnownUri.SoapNamespaceUri);

                while (true)
                {
                    if (reader.IsStartElement())
                    {
                        if (
                            (reader.NamespaceURI == WsWellKnownUri.WsaNamespaceUri_2005_08) ||
                            (reader.NamespaceURI == WsWellKnownUri.WsaNamespaceUri_2004_08) 
                           )
                        {
                            switch (reader.LocalName)
                            {
                                case "MessageID":
                                    if ((_messageId = reader.ReadElementString()) == String.Empty)
                                    {
                                        throw new XmlException("MessageID");
                                    }

                                    headerElements |= RequiredHeaderElement.MessageID;
                                    break;
                                case "RelatesTo":
                                    if ((_relatesTo = reader.ReadElementString()) == String.Empty)
                                    {
                                        throw new XmlException("RelatesTo");
                                    }
                                    break;
                                case "To":
                                    if ((_to = reader.ReadElementString()) == String.Empty)
                                    {
                                        throw new XmlException("To");
                                    }

                                    // If this is a URI peal off the transport address
                                    if (To.IndexOf("http://") == 0)
                                    {
                                        int pathIndex = _to.Substring(7).IndexOf('/');
                                        if (pathIndex != -1)
                                            _to = _to.Substring(pathIndex + 8);
                                    }

                                    headerElements |= RequiredHeaderElement.To;
                                    break;
                                case "Action":
                                    if ((_action = reader.ReadElementString()) == String.Empty)
                                    {
                                        throw new XmlException("Action");
                                    }

                                    headerElements |= RequiredHeaderElement.Action;
                                    break;
                                case "From":
#if DEBUG
                                    int depth = reader.Depth;
#endif
                                    _from = new WsWsaEndpointRef(reader);
#if DEBUG
                                    Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                                    break;
                                case "ReplyTo":
#if DEBUG
                                    depth = reader.Depth;
#endif
                                    _replyTo = new WsWsaEndpointRef(reader);
#if DEBUG
                                    Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                                    if (ReplyTo.Address.AbsoluteUri != WsWellKnownUri.WsaAnonymousUri &&
                                        ReplyTo.Address.AbsoluteUri != WsWellKnownUri.WsaAnonymousRoleUri)
                                    {
                                        throw new WsFaultException(this, WsFaultType.WsaInvalidMessageInformationHeader, "R0031");
                                    }
                                    break;
                                case "FaultTo":
#if DEBUG
                                    depth = reader.Depth;
#endif
                                    _faultTo = new WsWsaEndpointRef(reader);
#if DEBUG
                                    Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                                    break;
                                default:
                                    reader.Skip(); //unknown item from WSA namespace, should we store it?
                                    break;
                            }
                        }
                        else
                        {
                            // unknown item, need to store it for future reference
#if DEBUG
                            int depth = reader.Depth;
#endif
                            _any.Add(new WsXmlNode(reader));
#if DEBUG
                            Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                reader.ReadEndElement(); // Header
            }
            catch (XmlException e)
            {
                throw new WsFaultException(this, WsFaultType.WsaInvalidMessageInformationHeader, e.ToString());
            }

            //if (headerElements != RequiredHeaderElement.All)
            //{
            //    throw new WsFaultException(this, WsFaultType.WsaMessageInformationHeaderRequired);
            //}
        }
 /// <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;
 }
예제 #11
0
        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();

        }
예제 #12
0
        internal void ParseHeader(XmlReader reader, ProtocolVersion version)
        {
            RequiredHeaderElement headerElements = RequiredHeaderElement.None;

            ProtocolVersion altVer = version is ProtocolVersion10 ? (ProtocolVersion)new ProtocolVersion11() : (ProtocolVersion)new ProtocolVersion10();

            bool isFault = false;

            try
            {
                reader.ReadStartElement("Header", WsWellKnownUri.SoapNamespaceUri);

                while (true)
                {
                    if (reader.IsStartElement())
                    {

                        if (reader.NamespaceURI == version.AddressingNamespace ||
                            reader.NamespaceURI == altVer.AddressingNamespace)
                        {
                            switch (reader.LocalName)
                            {
                                case "MessageID":
                                    if ((_messageId = reader.ReadElementString()) == String.Empty)
                                    {
                                        throw new XmlException("MessageID");
                                    }

                                    headerElements |= RequiredHeaderElement.MessageID;
                                    break;
                                case "RelatesTo":
                                    if ((_relatesTo = reader.ReadElementString()) == String.Empty)
                                    {
                                        throw new XmlException("RelatesTo");
                                    }
                                    break;
                                case "To":
                                    if ((_to = reader.ReadElementString()) == String.Empty)
                                    {
                                        throw new XmlException("To");
                                    }

                                    // If this is a URI peal off the transport address
                                    if (To.IndexOf("http://") == 0)
                                    {
                                        int pathIndex = _to.Substring(7).IndexOf('/');
                                        if (pathIndex != -1)
                                            _to = _to.Substring(pathIndex + 8);
                                    }

                                    headerElements |= RequiredHeaderElement.To;
                                    break;
                                case "Action":
                                    if ((_action = reader.ReadElementString()) == String.Empty)
                                    {
                                        throw new XmlException("Action");
                                    }
                                    
                                    if(_action == version.AddressingNamespace + "/fault")
                                    {
                                        isFault = true;
                                    }

                                    headerElements |= RequiredHeaderElement.Action;
                                    break;
                                case "From":
#if DEBUG
                                    int depth = reader.Depth;
#endif
                                    _from = new WsWsaEndpointRef(reader, reader.NamespaceURI);
#if DEBUG
                                    Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                                    break;
                                case "ReplyTo":
#if DEBUG
                                    depth = reader.Depth;
#endif
                                    _replyTo = new WsWsaEndpointRef(reader, reader.NamespaceURI);
#if DEBUG
                                    Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                                    break;
                                case "FaultTo":
#if DEBUG
                                    depth = reader.Depth;
#endif
                                    _faultTo = new WsWsaEndpointRef(reader, reader.NamespaceURI);
#if DEBUG
                                    Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                                    break;
                                default:
                                    reader.Skip(); //unknown item from WSA namespace, should we store it?
                                    break;
                            }
                        }
                        else
                        {
                            // unknown item, need to store it for future reference
#if DEBUG
                            int depth = reader.Depth;
#endif
                            _any.Add(new WsXmlNode(reader));
#if DEBUG
                            Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                reader.ReadEndElement(); // Header
            }
            catch (XmlException e)
            {
                throw new WsFaultException(this, WsFaultType.WsaInvalidMessageInformationHeader, e.ToString());
            }

            if(isFault)
            {
                WsFault.ThrowFaultException(reader, this);
            }

            // add more logic for determining required headers?  it is not this simple
            //if (headerElements != RequiredHeaderElement.All)
            //{
            //    throw new WsFaultException(this, WsFaultType.WsaMessageInformationHeaderRequired);
            //}
        }
예제 #13
0
        internal void ParseHeader(XmlReader reader)
        {
            RequiredHeaderElement headerElements = RequiredHeaderElement.None;

            try
            {
                reader.ReadStartElement("Header", WsWellKnownUri.SoapNamespaceUri);

                while (true)
                {
                    if (reader.IsStartElement())
                    {
                        if (
                            (reader.NamespaceURI == WsWellKnownUri.WsaNamespaceUri_2005_08) ||
                            (reader.NamespaceURI == WsWellKnownUri.WsaNamespaceUri_2004_08)
                            )
                        {
                            switch (reader.LocalName)
                            {
                            case "MessageID":
                                if ((_messageId = reader.ReadElementString()) == String.Empty)
                                {
                                    throw new XmlException("MessageID");
                                }

                                headerElements |= RequiredHeaderElement.MessageID;
                                break;

                            case "RelatesTo":
                                if ((_relatesTo = reader.ReadElementString()) == String.Empty)
                                {
                                    throw new XmlException("RelatesTo");
                                }
                                break;

                            case "To":
                                if ((_to = reader.ReadElementString()) == String.Empty)
                                {
                                    throw new XmlException("To");
                                }

                                // If this is a URI peal off the transport address
                                if (To.IndexOf("http://") == 0)
                                {
                                    int pathIndex = _to.Substring(7).IndexOf('/');
                                    if (pathIndex != -1)
                                    {
                                        _to = _to.Substring(pathIndex + 8);
                                    }
                                }

                                headerElements |= RequiredHeaderElement.To;
                                break;

                            case "Action":
                                if ((_action = reader.ReadElementString()) == String.Empty)
                                {
                                    throw new XmlException("Action");
                                }

                                headerElements |= RequiredHeaderElement.Action;
                                break;

                            case "From":
#if DEBUG
                                int depth = reader.Depth;
#endif
                                _from = new WsWsaEndpointRef(reader);
#if DEBUG
                                Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                                break;

                            case "ReplyTo":
#if DEBUG
                                depth = reader.Depth;
#endif
                                _replyTo = new WsWsaEndpointRef(reader);
#if DEBUG
                                Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                                if (ReplyTo.Address.AbsoluteUri != WsWellKnownUri.WsaAnonymousUri &&
                                    ReplyTo.Address.AbsoluteUri != WsWellKnownUri.WsaAnonymousRoleUri)
                                {
                                    throw new WsFaultException(this, WsFaultType.WsaInvalidMessageInformationHeader, "R0031");
                                }
                                break;

                            case "FaultTo":
#if DEBUG
                                depth = reader.Depth;
#endif
                                _faultTo = new WsWsaEndpointRef(reader);
#if DEBUG
                                Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                                break;

                            default:
                                reader.Skip();     //unknown item from WSA namespace, should we store it?
                                break;
                            }
                        }
                        else
                        {
                            // unknown item, need to store it for future reference
#if DEBUG
                            int depth = reader.Depth;
#endif
                            _any.Add(new WsXmlNode(reader));
#if DEBUG
                            Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                reader.ReadEndElement(); // Header
            }
            catch (XmlException e)
            {
                throw new WsFaultException(this, WsFaultType.WsaInvalidMessageInformationHeader, e.ToString());
            }

            //if (headerElements != RequiredHeaderElement.All)
            //{
            //    throw new WsFaultException(this, WsFaultType.WsaMessageInformationHeaderRequired);
            //}
        }
예제 #14
0
 /// <summary>
 /// Removes the first occurrence of a specific WsaEndpointRef object from the colleciton.
 /// </summary>
 /// <param name="endpointReference">
 /// The WsaEndpointRef object to remove from the collection. The value can be null.</param>
 public void Remove(WsWsaEndpointRef endpointReference)
 {
     lock (m_threadLock)
     {
         m_EndpointReferences.Remove(endpointReference);
     }
 }
예제 #15
0
        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);
        }
예제 #16
0
 /// <summary>
 /// Adds a WsaEndpointRef object to the end of the collection.
 /// </summary>
 /// <param name="value">The WsaEndpointRef object to be added to the end of the collection.
 /// The value can be null.
 /// </param>
 /// <returns>The index at which the WsaEndpointRef object has been added.</returns>
 public int Add(WsWsaEndpointRef value)
 {
     lock (m_threadLock)
     {
         return m_EndpointReferences.Add(value);
     }
 }
        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;
            }
        }
예제 #18
0
        internal void ParseHeader(XmlReader reader, ProtocolVersion version)
        {
            RequiredHeaderElement headerElements = RequiredHeaderElement.None;

            ProtocolVersion altVer = version is ProtocolVersion10 ? (ProtocolVersion) new ProtocolVersion11() : (ProtocolVersion) new ProtocolVersion10();

            bool isFault = false;

            try
            {
                reader.ReadStartElement("Header", WsWellKnownUri.SoapNamespaceUri);

                while (true)
                {
                    if (reader.IsStartElement())
                    {
                        if (reader.NamespaceURI == version.AddressingNamespace ||
                            reader.NamespaceURI == altVer.AddressingNamespace)
                        {
                            switch (reader.LocalName)
                            {
                            case "MessageID":
                                if ((_messageId = reader.ReadElementString()) == String.Empty)
                                {
                                    throw new XmlException("MessageID");
                                }

                                headerElements |= RequiredHeaderElement.MessageID;
                                break;

                            case "RelatesTo":
                                if ((_relatesTo = reader.ReadElementString()) == String.Empty)
                                {
                                    throw new XmlException("RelatesTo");
                                }
                                break;

                            case "To":
                                if ((_to = reader.ReadElementString()) == String.Empty)
                                {
                                    throw new XmlException("To");
                                }

                                // If this is a URI peal off the transport address
                                if (To.IndexOf("http://") == 0)
                                {
                                    int pathIndex = _to.Substring(7).IndexOf('/');
                                    if (pathIndex != -1)
                                    {
                                        _to = _to.Substring(pathIndex + 8);
                                    }
                                }

                                headerElements |= RequiredHeaderElement.To;
                                break;

                            case "Action":
                                if ((_action = reader.ReadElementString()) == String.Empty)
                                {
                                    throw new XmlException("Action");
                                }

                                if (_action == version.AddressingNamespace + "/fault")
                                {
                                    isFault = true;
                                }

                                headerElements |= RequiredHeaderElement.Action;
                                break;

                            case "From":
#if DEBUG
                                int depth = reader.Depth;
#endif
                                _from = new WsWsaEndpointRef(reader, reader.NamespaceURI);
#if DEBUG
                                Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                                break;

                            case "ReplyTo":
#if DEBUG
                                depth = reader.Depth;
#endif
                                _replyTo = new WsWsaEndpointRef(reader, reader.NamespaceURI);
#if DEBUG
                                Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                                break;

                            case "FaultTo":
#if DEBUG
                                depth = reader.Depth;
#endif
                                _faultTo = new WsWsaEndpointRef(reader, reader.NamespaceURI);
#if DEBUG
                                Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                                break;

                            default:
                                reader.Skip();     //unknown item from WSA namespace, should we store it?
                                break;
                            }
                        }
                        else
                        {
                            // unknown item, need to store it for future reference
#if DEBUG
                            int depth = reader.Depth;
#endif
                            _any.Add(new WsXmlNode(reader));
#if DEBUG
                            Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                reader.ReadEndElement(); // Header
            }
            catch (XmlException e)
            {
                throw new WsFaultException(this, WsFaultType.WsaInvalidMessageInformationHeader, e.ToString());
            }

            if (isFault)
            {
                WsFault.ThrowFaultException(reader, this);
            }

            // add more logic for determining required headers?  it is not this simple
            //if (headerElements != RequiredHeaderElement.All)
            //{
            //    throw new WsFaultException(this, WsFaultType.WsaMessageInformationHeaderRequired);
            //}
        }
예제 #19
0
        /// <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;
        }