Пример #1
0
        public async Task CheckXmlAnnotatedChoiceReturnServiceWsdl()
        {
            var wsdl = await GetWsdlFromMetaBodyWriter <XmlAnnotatedChoiceReturnService>(SoapSerializer.XmlSerializer);

            Trace.TraceInformation(wsdl);
            Assert.IsNotNull(wsdl);

            Assert.IsFalse(wsdl.Contains("name=\"\""));

            var root = XElement.Parse(wsdl);
            var nm   = Namespaces.CreateDefaultXmlNamespaceManager();

            var requestTypeElement = root.XPathSelectElement("//xsd:element[@name='GetResponseResponse']", nm);

            Assert.IsNotNull(requestTypeElement);

            var choiceElement = root.XPathSelectElement("//xsd:element[@name='GetResponseResponse']/xsd:complexType/xsd:sequence/xsd:choice", nm);

            Assert.IsNotNull(choiceElement);

            var resultResponseElement = root.XPathSelectElement("//xsd:element[@name='GetResponseResponse']/xsd:complexType/xsd:sequence/xsd:choice/xsd:element[@name='resultResp']", nm);

            Assert.IsNotNull(resultResponseElement);

            var integerElement = root.XPathSelectElement("//xsd:element[@name='GetResponseResponse']/xsd:complexType/xsd:sequence/xsd:choice/xsd:element[@name='integerNumber']", nm);

            Assert.IsNotNull(integerElement);

            var choiceComplexTypeElement = root.XPathSelectElement("//xsd:complexType[@name='ResultResponse']", nm);

            Assert.IsNotNull(choiceComplexTypeElement);
        }
Пример #2
0
        private async Task <string> GetWsdlFromMetaBodyWriter <T>(SoapSerializer serializer)
        {
            var service             = new ServiceDescription(typeof(T));
            var baseUrl             = "http://tempuri.org/";
            var xmlNamespaceManager = Namespaces.CreateDefaultXmlNamespaceManager();
            var bodyWriter          = serializer == SoapSerializer.DataContractSerializer
                                ? new MetaWCFBodyWriter(service, baseUrl, null) as BodyWriter
                                : new MetaBodyWriter(service, baseUrl, null, xmlNamespaceManager) as BodyWriter;
            var encoder         = new SoapMessageEncoder(MessageVersion.Soap12WSAddressingAugust2004, System.Text.Encoding.UTF8, XmlDictionaryReaderQuotas.Max, false, true);
            var responseMessage = Message.CreateMessage(encoder.MessageVersion, null, bodyWriter);

            responseMessage = new MetaMessage(responseMessage, service, null, xmlNamespaceManager);

            using (var memoryStream = new MemoryStream())
            {
                await encoder.WriteMessageAsync(responseMessage, memoryStream);

                memoryStream.Position = 0;

                using (var streamReader = new StreamReader(memoryStream))
                {
                    var result = streamReader.ReadToEnd();
                    return(result);
                }
            }
        }
Пример #3
0
        public async Task CheckXmlAnnotatedTypeServiceWsdl()
        {
            var wsdl = await GetWsdlFromMetaBodyWriter <XmlModelsService>(SoapSerializer.XmlSerializer);

            Trace.TraceInformation(wsdl);
            Assert.IsNotNull(wsdl);

            Assert.IsFalse(wsdl.Contains("name=\"\""));

            var root = XElement.Parse(wsdl);
            var nm   = Namespaces.CreateDefaultXmlNamespaceManager();

            var requestTypeElement = root.XPathSelectElement("//xsd:element[@name='RequestRoot']", nm);

            Assert.IsNotNull(requestTypeElement);

            var reponseTypeElement = root.XPathSelectElement("//xsd:element[@name='ResponseRoot']", nm);

            Assert.IsNotNull(reponseTypeElement);

            var referenceToExistingDynamicType = root.XPathSelectElement("//xsd:complexType[@name='TestResponseType']/xsd:sequence/xsd:element[@name='DataList3' and @type='tns:ArrayOfTestDataTypeData']", nm);

            Assert.IsNotNull(referenceToExistingDynamicType);

            var selfContainedType = root.XPathSelectElement("//xsd:complexType[@name='TestResponseType']/xsd:sequence/xsd:element[@name='Data' and @minOccurs='0'and @maxOccurs='unbounded' and not(@type)]", nm);

            Assert.IsNotNull(selfContainedType);

            var dynamicTypeElement = root.XPathSelectElement("//xsd:complexType[@name='ArrayOfTestDataTypeData']/xsd:sequence/xsd:element[@name='Data']", nm);

            Assert.IsNotNull(dynamicTypeElement);

            var dynamicTypeElement2 = root.XPathSelectElement("//xsd:complexType[@name='ArrayOfTestDataTypeData1']/xsd:sequence/xsd:element[@name='Data2']", nm);

            Assert.IsNotNull(dynamicTypeElement2);

            var choiceTypeElement = root.XPathSelectElement("//xsd:complexType[@name='TestResponseType']/xsd:sequence/xsd:choice[@minOccurs='0'and @maxOccurs='unbounded']/xsd:element[@name='Data4']", nm);

            Assert.IsNotNull(choiceTypeElement);

            var choiceTypeElement2 = root.XPathSelectElement("//xsd:complexType[@name='TestResponseType']/xsd:sequence/xsd:choice[@minOccurs='0'and @maxOccurs='unbounded']/xsd:element[@name='Data5']", nm);

            Assert.IsNotNull(choiceTypeElement2);

            var propRootAttribute = root.XPathSelectElement("//xsd:attribute[@name='PropRoot']", nm);

            Assert.IsNotNull(propRootAttribute);

            var propIgnoreAttribute = root.XPathSelectElement("//xsd:attribute[@name='PropIgnore']", nm);

            Assert.IsNull(propIgnoreAttribute);

            var propAnonAttribute = root.XPathSelectElement("//xsd:attribute[@name='PropAnonymous']", nm);

            Assert.IsNotNull(propAnonAttribute);
        }
Пример #4
0
        public async Task CheckXmlSchemaProviderTypeServiceWsdl()
        {
            var wsdl = await GetWsdlFromMetaBodyWriter <XmlSchemaProviderTypeService>(SoapSerializer.XmlSerializer);

            Trace.TraceInformation(wsdl);
            Assert.IsNotNull(wsdl);

            var root = XElement.Parse(wsdl);
            var nm   = Namespaces.CreateDefaultXmlNamespaceManager();

            var responseDateElem = root.XPathSelectElement("//xsd:element[@name='GetDateResponse']/xsd:complexType/xsd:sequence/xsd:element[@name='GetDateResult' and contains(@type, ':date')]", nm);

            Assert.IsNotNull(responseDateElem);
        }
Пример #5
0
        public async Task CheckMessageHeadersServiceWsdl()
        {
            var wsdl = await GetWsdlFromMetaBodyWriter <MessageHeadersService>(SoapSerializer.XmlSerializer);

            Trace.TraceInformation(wsdl);
            Assert.IsNotNull(wsdl);

            Assert.IsFalse(wsdl.Contains("name=\"\""));

            var root = XElement.Parse(wsdl);
            var nm   = Namespaces.CreateDefaultXmlNamespaceManager();

            var stringPropertyElement = root.XPathSelectElement("//xsd:element[@name='ModifiedStringProperty']", nm);

            Assert.IsNotNull(stringPropertyElement);
        }
Пример #6
0
        public async Task CheckUnqualifiedMembersService()
        {
            var wsdl = await GetWsdlFromMetaBodyWriter <UnqualifiedMembersService>(SoapSerializer.XmlSerializer);

            Trace.TraceInformation(wsdl);

            var root = XElement.Parse(wsdl);
            var nm   = Namespaces.CreateDefaultXmlNamespaceManager();

            bool allNeededAreUnqualified = root.XPathSelectElements($"//xsd:complexType[@name='{nameof(TypeWithUnqualifiedMembers)}' or @name='{nameof(UnqType2)}']/xsd:sequence/xsd:element[contains(@name, 'Unqualified')]", nm)
                                           .All(x => x.Attribute("form")?.Value.Equals("unqualified") == true);

            Assert.IsTrue(allNeededAreUnqualified);

            bool allNeededAreQualified = root.XPathSelectElements($"//xsd:complexType[@name='{nameof(TypeWithUnqualifiedMembers)}' or @name='{nameof(UnqType2)}']/xsd:sequence/xsd:element[contains(@name, 'Qualified')]", nm)
                                         .All(x => x.Attribute("form")?.Value.Equals("unqualified") != true);

            Assert.IsTrue(allNeededAreQualified);
        }
Пример #7
0
        public async Task CheckDateTimeOffsetServiceWsdl()
        {
            var    nm       = Namespaces.CreateDefaultXmlNamespaceManager();
            string systemNs = "http://schemas.datacontract.org/2004/07/System";

            var wsdl = await GetWsdlFromMetaBodyWriter <DateTimeOffsetService>(SoapSerializer.XmlSerializer);

            var root             = XElement.Parse(wsdl);
            var responseDateElem = root.XPathSelectElement($"//xsd:element[@name='MethodResponse']/xsd:complexType/xsd:sequence/xsd:element[@name='MethodResult']", nm);

            Assert.IsTrue(responseDateElem.ToString().Contains(systemNs));

            var wsdlWCF = await GetWsdlFromMetaBodyWriter <DateTimeOffsetService>(SoapSerializer.DataContractSerializer);

            var rootWCF             = XElement.Parse(wsdlWCF);
            var responseDateElemWCF = rootWCF.XPathSelectElement($"//xsd:element[@name='MethodResponse']/xsd:complexType/xsd:sequence/xsd:element[@name='MethodResult']", nm);

            Assert.IsTrue(responseDateElemWCF.ToString().Contains(systemNs));
            var dayOfYearElem = GetElements(rootWCF, _xmlSchema + "element").SingleOrDefault(a => a.Attribute("name")?.Value.Equals("DayOfYear") == true);

            Assert.IsNull(dayOfYearElem);
        }