static void CheckSoapBinding (object extension, string transport, TestLabel label)
		{
			label.EnterScope ("soap");
			Assert.That (extension, Is.InstanceOfType (typeof (WS.SoapBinding)), label.Get ());
			var soap = (WS.SoapBinding)extension;
			Assert.That (soap.Style, Is.EqualTo (WS.SoapBindingStyle.Document), label.Get ());
			Assert.That (soap.Transport, Is.EqualTo (transport), label.Get ());
			Assert.That (soap.Required, Is.False, label.Get ());
			label.LeaveScope ();
		}
        static void TestSoap(WS.SoapOperationBinding soap, bool soap12, TestLabel label)
        {
            label.EnterScope("soap");
            var type = soap12 ? typeof(WS.Soap12OperationBinding) : typeof(WS.SoapOperationBinding);

            Assert.That(soap.GetType(), Is.EqualTo(type), label.Get());
            Assert.That(soap.Style, Is.EqualTo(WS.SoapBindingStyle.Document), label.Get());
            Assert.That(soap.SoapAction, Is.EqualTo("http://tempuri.org/IMyContract/Hello"), label.Get());
            Assert.That(soap.Required, Is.False, label.Get());
            label.LeaveScope();
        }
Beispiel #3
0
        public static void CheckExport(
            WsdlExporter exporter, QName contractName, string bindingName,
            int countEndpoints, TestLabel label)
        {
            Assert.That(exporter.GeneratedWsdlDocuments, Is.Not.Null, label.Get());
            Assert.That(exporter.GeneratedWsdlDocuments.Count, Is.EqualTo(1), label.Get());

            var wsdl = exporter.GeneratedWsdlDocuments [0];

            CheckExport(wsdl, contractName, bindingName, countEndpoints, label);
        }
        static void CheckSoapBinding(object extension, string transport, TestLabel label)
        {
            label.EnterScope("soap");
            Assert.That(extension, Is.InstanceOfType(typeof(WS.SoapBinding)), label.Get());
            var soap = (WS.SoapBinding)extension;

            Assert.That(soap.Style, Is.EqualTo(WS.SoapBindingStyle.Document), label.Get());
            Assert.That(soap.Transport, Is.EqualTo(transport), label.Get());
            Assert.That(soap.Required, Is.False, label.Get());
            label.LeaveScope();
        }
        static void TestSoapBody(WS.SoapBodyBinding soap, bool soap12, TestLabel label)
        {
            label.EnterScope("soap-body");
            var type = soap12 ? typeof(WS.Soap12BodyBinding) : typeof(WS.SoapBodyBinding);

            Assert.That(soap.GetType(), Is.EqualTo(type), label.Get());
            Assert.That(soap.Encoding, Is.Empty, label.Get());
            Assert.That(soap.Namespace, Is.Empty, label.Get());
            Assert.That(soap.Parts, Is.Null, label.Get());
            Assert.That(soap.Use, Is.EqualTo(WS.SoapBindingUse.Literal), label.Get());
            label.LeaveScope();
        }
        static void TestSoapMessage(WS.MessageBinding binding, bool soap12, TestLabel label)
        {
            label.EnterScope(binding is WS.InputBinding ? "input" : "output");

            Assert.That(binding, Is.Not.Null, label.Get());
            Assert.That(binding.Name, Is.Null, label.Get());
            Assert.That(binding.ExtensibleAttributes, Is.Null, label.Get());
            Assert.That(binding.Extensions, Is.Not.Null, label.Get());
            Assert.That(binding.Extensions.Count, Is.EqualTo(1), label.Get());
            Assert.That(binding.Extensions [0], Is.InstanceOfType(typeof(WS.SoapBodyBinding)), label.Get());
            var body = (WS.SoapBodyBinding)binding.Extensions [0];

            TestSoapBody(body, soap12, label);
            label.LeaveScope();
        }
Beispiel #7
0
		public void BasicHttpBinding_ImportBinding ()
		{
			var label = new TestLabel ("BasicHttpBinding_ImportBinding");
			
			var doc = TestContext.LoadMetadata ("BasicHttp");
			var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;
			var wsdlBinding = sd.Bindings [0];
			
			var importer = new WsdlImporter (doc);
			
			Assert.That (sd.Bindings, Is.Not.Null, label.Get ());
			Assert.That (sd.Bindings.Count, Is.EqualTo (1), label.Get ());
			
			var binding = importer.ImportBinding (wsdlBinding);
			BindingTestAssertions.CheckImportErrors (importer, label);
			Assert.That (binding, Is.Not.Null, label.Get ());
		}
 static void CheckEndpoint(ServiceEndpoint endpoint, string uri, TestLabel label)
 {
     label.EnterScope("endpoint");
     Assert.That(endpoint.ListenUri, Is.EqualTo(new Uri(uri)), label.Get());
     Assert.That(endpoint.ListenUriMode, Is.EqualTo(ListenUriMode.Explicit), label.Get());
     Assert.That(endpoint.Contract, Is.Not.Null, label.Get());
     Assert.That(endpoint.Contract.Name, Is.EqualTo("MyContract"), label.Get());
     Assert.That(endpoint.Address, Is.Not.Null, label.Get());
     Assert.That(endpoint.Address.Uri, Is.EqualTo(new Uri(uri)), label.Get());
     Assert.That(endpoint.Address.Identity, Is.Null, label.Get());
     Assert.That(endpoint.Address.Headers, Is.Not.Null, label.Get());
     Assert.That(endpoint.Address.Headers.Count, Is.EqualTo(0), label.Get());
     label.LeaveScope();
 }
Beispiel #9
0
        public void BasicHttpBinding_ImportBinding()
        {
            var label = new TestLabel("BasicHttpBinding_ImportBinding");

            var doc         = TestContext.LoadMetadata("BasicHttp");
            var sd          = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;
            var wsdlBinding = sd.Bindings [0];

            var importer = new WsdlImporter(doc);

            Assert.That(sd.Bindings, Is.Not.Null, label.Get());
            Assert.That(sd.Bindings.Count, Is.EqualTo(1), label.Get());

            var binding = importer.ImportBinding(wsdlBinding);

            BindingTestAssertions.CheckImportErrors(importer, label);
            Assert.That(binding, Is.Not.Null, label.Get());
        }
        public static void AssertConfig(MetadataSet metadata, XmlDocument xml, TestLabel label)
        {
            label.EnterScope("import");
            var importer  = new WsdlImporter(metadata);
            var endpoints = importer.ImportAllEndpoints();

            CheckImportErrors(importer, label);
            Assert.That(endpoints.Count, Is.AtLeast(1), label.Get());
            label.LeaveScope();

            var nav = xml.CreateNavigator();

            // FIXME: Check endpoints.

            label.EnterScope("endpoints");
            var endpointIter = nav.Select("/configuration/system.serviceModel/client/endpoint");

            Assert.That(endpointIter.Count, Is.EqualTo(endpoints.Count), label.Get());

            label.LeaveScope();
        }
        public static void TestOperation(MetadataSet metadata, bool soap12, TestLabel label)
        {
            label.EnterScope("TestOperation");

            label.EnterScope("metadata");
            WS.ServiceDescription sd = null;
            foreach (var ms in metadata.MetadataSections)
            {
                if (!ms.Dialect.Equals("http://schemas.xmlsoap.org/wsdl/"))
                {
                    continue;
                }
                sd = ms.Metadata as WS.ServiceDescription;
            }
            Assert.That(sd, Is.Not.Null, label.Get());
            Assert.That(sd.Bindings, Is.Not.Null, label.Get());
            Assert.That(sd.Bindings.Count, Is.EqualTo(1), label.Get());
            var binding = sd.Bindings [0];

            label.LeaveScope();

            label.EnterScope("operation");
            Assert.That(binding.Operations, Is.Not.Null, label.Get());
            Assert.That(binding.Operations.Count, Is.EqualTo(1), label.Get());
            var op = binding.Operations [0];

            Assert.That(op.Name, Is.EqualTo("Hello"), label.Get());
            Assert.That(op.ExtensibleAttributes, Is.Null, label.Get());

            label.EnterScope("extensions");
            Assert.That(op.Extensions, Is.Not.Null, label.Get());
            Assert.That(op.Extensions.Count, Is.EqualTo(1), label.Get());
            Assert.That(op.Extensions [0], Is.InstanceOfType(typeof(WS.SoapOperationBinding)), label.Get());
            var soap = (WS.SoapOperationBinding)op.Extensions [0];

            TestSoap(soap, soap12, label);
            label.LeaveScope();

            TestSoapMessage(op.Input, soap12, label);
            TestSoapMessage(op.Output, soap12, label);
            label.LeaveScope();              // operation

            label.LeaveScope();
        }
Beispiel #12
0
		public void BasicHttpBinding_ImportEndpoint ()
		{
			var label = new TestLabel ("BasicHttpBinding_ImportEndpoint");
			
			var doc = TestContext.LoadMetadata ("BasicHttp");
			var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;
			
			label.EnterScope ("wsdl");
			Assert.That (sd.Services, Is.Not.Null, label.Get ());
			Assert.That (sd.Services.Count, Is.EqualTo (1), label.Get ());
			
			var service = sd.Services [0];
			Assert.That (service.Ports, Is.Not.Null, label.Get ());
			Assert.That (service.Ports.Count, Is.EqualTo (1), label.Get ());
			label.LeaveScope ();
			
			var importer = new WsdlImporter (doc);
			
			var port = importer.ImportEndpoint (service.Ports [0]);
			BindingTestAssertions.CheckImportErrors (importer, label);
			Assert.That (port, Is.Not.Null, label.Get ());
		}
        public static PolicyAssertionCollection AssertPolicy(
            WS.Binding binding, TestLabel label)
        {
            label.EnterScope("FindPolicy");
            XmlElement policy = null;

            foreach (var extension in binding.Extensions)
            {
                var xml = extension as XmlElement;
                if (xml == null)
                {
                    continue;
                }
                Assert.That(policy, Is.Null, label.Get());
                policy = xml;
            }
            Assert.That(policy, Is.Not.Null, label.Get());
            try {
                return(AssertPolicy(binding.ServiceDescription, policy, label));
            } finally {
                label.LeaveScope();
            }
        }
Beispiel #14
0
        public void BasicHttpBinding_ImportEndpoint()
        {
            var label = new TestLabel("BasicHttpBinding_ImportEndpoint");

            var doc = TestContext.LoadMetadata("BasicHttp");
            var sd  = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

            label.EnterScope("wsdl");
            Assert.That(sd.Services, Is.Not.Null, label.Get());
            Assert.That(sd.Services.Count, Is.EqualTo(1), label.Get());

            var service = sd.Services [0];

            Assert.That(service.Ports, Is.Not.Null, label.Get());
            Assert.That(service.Ports.Count, Is.EqualTo(1), label.Get());
            label.LeaveScope();

            var importer = new WsdlImporter(doc);

            var port = importer.ImportEndpoint(service.Ports [0]);

            BindingTestAssertions.CheckImportErrors(importer, label);
            Assert.That(port, Is.Not.Null, label.Get());
        }
        public static PolicyAssertionCollection AssertPolicy(
            WS.ServiceDescription sd, XmlElement element, TestLabel label)
        {
            label.EnterScope("wsp:Policy");
            Assert.That(element.NamespaceURI, Is.EqualTo(WspNamespace), label.Get());
            Assert.That(element.LocalName, Is.EqualTo("Policy") | Is.EqualTo("PolicyReference"), label.Get());

            var policy = ResolvePolicy(sd, element);

            Assert.That(policy, Is.Not.Null, label.Get());

            label.EnterScope("wsp:ExactlyOne");
            var exactlyOne = AssertExactlyOneChildElement(policy);

            Assert.That(exactlyOne, Is.Not.Null, label.Get());
            Assert.That(exactlyOne.NamespaceURI, Is.EqualTo(WspNamespace), label.Get());
            Assert.That(exactlyOne.LocalName, Is.EqualTo("ExactlyOne"), label.Get());
            label.LeaveScope();

            label.EnterScope("wsp:Any");
            var all = AssertExactlyOneChildElement(exactlyOne);

            Assert.That(all, Is.Not.Null, label.Get());
            Assert.That(all.NamespaceURI, Is.EqualTo(WspNamespace), label.Get());
            Assert.That(all.LocalName, Is.EqualTo("All"), label.Get());
            label.LeaveScope();

            var collection = new PolicyAssertionCollection();

            label.EnterScope("assertions");
            foreach (var node in all.ChildNodes)
            {
                if (node is XmlWhitespace)
                {
                    continue;
                }
                Assert.That(node, Is.InstanceOfType(typeof(XmlElement)), label.ToString());
                collection.Add((XmlElement)node);
            }
            label.LeaveScope();

            label.LeaveScope();

            return(collection);
        }
Beispiel #16
0
		public static void TestOperation (MetadataSet metadata, bool soap12, TestLabel label)
		{
			label.EnterScope ("TestOperation");

			label.EnterScope ("metadata");
			WS.ServiceDescription sd = null;
			foreach (var ms in metadata.MetadataSections) {
				if (!ms.Dialect.Equals ("http://schemas.xmlsoap.org/wsdl/"))
					continue;
				sd = ms.Metadata as WS.ServiceDescription;
			}
			Assert.That (sd, Is.Not.Null, label.Get ());
			Assert.That (sd.Bindings, Is.Not.Null, label.Get ());
			Assert.That (sd.Bindings.Count, Is.EqualTo (1), label.Get ());
			var binding = sd.Bindings [0];
			label.LeaveScope ();

			label.EnterScope ("operation");
			Assert.That (binding.Operations, Is.Not.Null, label.Get ());
			Assert.That (binding.Operations.Count, Is.EqualTo (1), label.Get ());
			var op = binding.Operations [0];

			Assert.That (op.Name, Is.EqualTo ("Hello"), label.Get ());
			Assert.That (op.ExtensibleAttributes, Is.Null, label.Get ());

			label.EnterScope ("extensions");
			Assert.That (op.Extensions, Is.Not.Null, label.Get ());
			Assert.That (op.Extensions.Count, Is.EqualTo (1), label.Get ());
			Assert.That (op.Extensions [0], Is.InstanceOfType (typeof (WS.SoapOperationBinding)), label.Get ());
			var soap = (WS.SoapOperationBinding)op.Extensions [0];
			TestSoap (soap, soap12, label);
			label.LeaveScope ();

			TestSoapMessage (op.Input, soap12, label);
			TestSoapMessage (op.Output, soap12, label);
			label.LeaveScope (); // operation

			label.LeaveScope ();
		}
Beispiel #17
0
		static void TestSoap (WS.SoapOperationBinding soap, bool soap12, TestLabel label)
		{
			label.EnterScope ("soap");
			var type = soap12 ? typeof (WS.Soap12OperationBinding) : typeof (WS.SoapOperationBinding);
			Assert.That (soap.GetType (), Is.EqualTo (type), label.Get ());
			Assert.That (soap.Style, Is.EqualTo (WS.SoapBindingStyle.Document), label.Get ());
			Assert.That (soap.SoapAction, Is.EqualTo ("http://tempuri.org/IMyContract/Hello"), label.Get ());
			Assert.That (soap.Required, Is.False, label.Get ());
			label.LeaveScope ();
		}
Beispiel #18
0
		public void BasicHttpBinding_Error ()
		{
			var label = new TestLabel ("BasicHttpBinding_Error");
			
			var doc = TestContext.LoadMetadata ("http-error.xml");
			var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;
			var wsdlBinding = sd.Bindings [0];
			
			var importer = new WsdlImporter (doc);
			
			label.EnterScope ("all");
			
			var bindings = importer.ImportAllBindings ();
			Assert.That (bindings, Is.Not.Null, label.Get ());
			Assert.That (bindings.Count, Is.EqualTo (0), label.Get ());
			
			label.EnterScope ("errors");
			Assert.That (importer.Errors, Is.Not.Null, label.Get ());
			Assert.That (importer.Errors.Count, Is.EqualTo (1), label.Get ());
			
			var error = importer.Errors [0];
			Assert.That (error.IsWarning, Is.False, label.Get ());
			label.LeaveScope ();
			label.LeaveScope ();
			
			label.EnterScope ("single");
			
			try {
				importer.ImportBinding (wsdlBinding);
				Assert.Fail (label.Get ());
			} catch {
				;
			}
			
			Assert.That (importer.Errors.Count, Is.EqualTo (1), label.Get ());
			
			label.LeaveScope ();
			
			label.EnterScope ("single-first");
			
			var importer2 = new WsdlImporter (doc);
			
			try {
				importer2.ImportBinding (wsdlBinding);
				Assert.Fail (label.Get ());
			} catch {
				;
			}
			
			Assert.That (importer2.Errors.Count, Is.EqualTo (1), label.Get ());
			
			try {
				importer2.ImportBinding (wsdlBinding);
				Assert.Fail (label.Get ());
			} catch {
				;
			}
			
			var bindings2 = importer.ImportAllBindings ();
			Assert.That (bindings2, Is.Not.Null, label.Get ());
			Assert.That (bindings2.Count, Is.EqualTo (0), label.Get ());
			
			label.LeaveScope ();
		}
Beispiel #19
0
		public static PolicyAssertionCollection AssertPolicy (
			WS.ServiceDescription sd, XmlElement element, TestLabel label)
		{
			label.EnterScope ("wsp:Policy");
			Assert.That (element.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ());
			Assert.That (element.LocalName, Is.EqualTo ("Policy") | Is.EqualTo ("PolicyReference"), label.Get ());

			var policy = ResolvePolicy (sd, element);
			Assert.That (policy, Is.Not.Null, label.Get ());

			label.EnterScope ("wsp:ExactlyOne");
			var exactlyOne = AssertExactlyOneChildElement (policy);
			Assert.That (exactlyOne, Is.Not.Null, label.Get ());
			Assert.That (exactlyOne.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ());
			Assert.That (exactlyOne.LocalName, Is.EqualTo ("ExactlyOne"), label.Get ());
			label.LeaveScope ();

			label.EnterScope ("wsp:Any");
			var all = AssertExactlyOneChildElement (exactlyOne);
			Assert.That (all, Is.Not.Null, label.Get ());
			Assert.That (all.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ());
			Assert.That (all.LocalName, Is.EqualTo ("All"), label.Get ());
			label.LeaveScope ();

			var collection = new PolicyAssertionCollection ();

			label.EnterScope ("assertions");
			foreach (var node in all.ChildNodes) {
				if (node is XmlWhitespace)
					continue;
				Assert.That (node, Is.InstanceOfType (typeof (XmlElement)), label.ToString ());
				collection.Add ((XmlElement)node);
			}
			label.LeaveScope ();

			label.LeaveScope ();

			return collection;
		}
Beispiel #20
0
		public static void CheckExport (
			WS.ServiceDescription wsdl, QName contractName, string bindingName,
			int countEndpoints, TestLabel label)
		{
			label.EnterScope ("ServiceDescription");
			Assert.That (wsdl.TargetNamespace, Is.EqualTo (contractName.Namespace), label.Get ());
			Assert.That (wsdl.Name, Is.EqualTo ("service"), label.Get ());
			label.LeaveScope ();

			label.EnterScope ("Bindings");
			Assert.That (wsdl.Bindings, Is.Not.Null, label.Get ());
			Assert.That (wsdl.Bindings.Count, Is.EqualTo (countEndpoints), label.Get ());
			
			for (int i = 0; i < countEndpoints; i++) {
				label.EnterScope (string.Format ("#{0}", i+1));
				var binding = wsdl.Bindings [i];
				var expectedName = string.Format (
					"{0}_{1}{2}", bindingName, contractName.Name,
					i > 0 ? i.ToString () : "");
				Assert.That (binding.Name, Is.EqualTo (expectedName), label.Get ());
				Assert.That (binding.Type, Is.EqualTo (contractName), label.Get ());
				label.LeaveScope ();
			}
			label.LeaveScope ();
			
			label.EnterScope ("PortTypes");
			Assert.That (wsdl.PortTypes, Is.Not.Null, label.Get ());
			Assert.That (wsdl.PortTypes.Count, Is.EqualTo (1), label.Get ());
			var portType = wsdl.PortTypes [0];
			Assert.That (portType.Name, Is.EqualTo (contractName.Name), label.Get ());
			label.LeaveScope ();
			
			label.EnterScope ("Services");
			Assert.That (wsdl.Services, Is.Not.Null, label.Get ());
			Assert.That (wsdl.Services.Count, Is.EqualTo (1), label.Get ());
			var service = wsdl.Services [0];
			Assert.That (service.Name, Is.EqualTo ("service"), label.Get ());
			label.LeaveScope ();
			
			label.EnterScope ("Ports");
			Assert.That (service.Ports, Is.Not.Null, label.Get ());
			Assert.That (service.Ports.Count, Is.EqualTo (countEndpoints), label.Get ());
			for (int i = 0; i < countEndpoints; i++) {
				label.EnterScope (string.Format ("#{0}", i+1));
				var port = service.Ports [i];
				var expectedName = string.Format (
					"{0}_{1}{2}", bindingName, contractName.Name,
					i > 0 ? i.ToString () : "");
				var qname = new QName (expectedName, contractName.Namespace);
				Assert.That (port.Name, Is.EqualTo (qname.Name), label.Get ());
				Assert.That (port.Binding, Is.EqualTo (qname), label.Get ());
				label.LeaveScope ();
			}
			label.LeaveScope ();
		}
Beispiel #21
0
		public static void CheckExport (
			WsdlExporter exporter, QName contractName, string bindingName,
			int countEndpoints, TestLabel label)
		{
			Assert.That (exporter.GeneratedWsdlDocuments, Is.Not.Null, label.Get ());
			Assert.That (exporter.GeneratedWsdlDocuments.Count, Is.EqualTo (1), label.Get ());
			
			var wsdl = exporter.GeneratedWsdlDocuments [0];
			CheckExport (wsdl, contractName, bindingName, countEndpoints, label);
		}
Beispiel #22
0
		public void Mtom_Policy ()
		{
			var label = new TestLabel ("Mtom_Policy");
			var contract = new ContractDescription ("MyContract");
			var binding = new BasicHttpBinding ();
			binding.MessageEncoding = WSMessageEncoding.Mtom;

			var endpoint = new ServiceEndpoint (
				contract, binding, new EndpointAddress (HttpUri));

			var exporter = new WsdlExporter ();
			exporter.ExportEndpoint (endpoint);

			Assert.That (exporter.GeneratedWsdlDocuments, Is.Not.Null, label.Get ());
			Assert.That (exporter.GeneratedWsdlDocuments.Count, Is.EqualTo (1), label.Get ());
			var wsdl = exporter.GeneratedWsdlDocuments [0];

			Assert.That (wsdl.Bindings, Is.Not.Null, label.Get ());
			Assert.That (wsdl.Bindings.Count, Is.EqualTo (1), label.Get ());

			var wsb = wsdl.Bindings [0];
			label.EnterScope ("Binding");
			Assert.That (wsb.Extensions, Is.Not.Null, label.Get ());
			Assert.That (wsb.Extensions.Count, Is.EqualTo (2), label.Get ());
			label.LeaveScope ();

			label.EnterScope ("Extensions");
			WS.SoapBinding soap = null;
			XmlElement xml = null;
			foreach (var extension in wsb.Extensions) {
				if (extension is WS.SoapBinding)
					soap = (WS.SoapBinding)extension;
				else if (extension is XmlElement)
					xml = (XmlElement)extension;
				else
					Assert.Fail ("Unknown extension.", label);
			}

			Assert.That (soap, Is.Not.Null, label.Get ());
			Assert.That (xml, Is.Not.Null, label.Get ());
			label.LeaveScope ();

			label.EnterScope ("Policy");
			var assertions = BindingTestAssertions.AssertPolicy (wsdl, xml, label);
			Assert.That (assertions.Count, Is.EqualTo (1), label.Get ());
			var assertion = assertions [0];
			Assert.That (assertion.NamespaceURI, Is.EqualTo ("http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization"), label.Get ());
			Assert.That (assertion.LocalName, Is.EqualTo ("OptimizedMimeSerialization"), label.Get ());
			label.LeaveScope ();
		}
Beispiel #23
0
        public void BasicHttpBinding_Error2()
        {
            var label = new TestLabel("BasicHttpBinding_Error2");

            var doc = TestContext.LoadMetadata("http-error.xml");
            var sd  = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

            label.EnterScope("wsdl");
            Assert.That(sd.Services, Is.Not.Null, label.Get());
            Assert.That(sd.Services.Count, Is.EqualTo(1), label.Get());

            var service = sd.Services [0];

            Assert.That(service.Ports, Is.Not.Null, label.Get());
            Assert.That(service.Ports.Count, Is.EqualTo(1), label.Get());
            label.LeaveScope();

            var importer = new WsdlImporter(doc);

            label.EnterScope("all");

            var endpoints = importer.ImportAllEndpoints();

            Assert.That(endpoints, Is.Not.Null, label.Get());
            Assert.That(endpoints.Count, Is.EqualTo(0), label.Get());

            label.EnterScope("errors");
            Assert.That(importer.Errors, Is.Not.Null, label.Get());
            Assert.That(importer.Errors.Count, Is.EqualTo(2), label.Get());

            Assert.That(importer.Errors [0].IsWarning, Is.False, label.Get());
            Assert.That(importer.Errors [1].IsWarning, Is.False, label.Get());
            label.LeaveScope();
            label.LeaveScope();

            label.EnterScope("single");

            try {
                importer.ImportEndpoint(service.Ports [0]);
                Assert.Fail(label.Get());
            } catch {
                ;
            }

            Assert.That(importer.Errors.Count, Is.EqualTo(2), label.Get());

            label.LeaveScope();

            label.EnterScope("single-first");

            var importer2 = new WsdlImporter(doc);

            try {
                importer2.ImportEndpoint(service.Ports [0]);
                Assert.Fail(label.Get());
            } catch {
                ;
            }

            Assert.That(importer2.Errors.Count, Is.EqualTo(2), label.Get());

            try {
                importer2.ImportEndpoint(service.Ports [0]);
                Assert.Fail(label.Get());
            } catch {
                ;
            }

            var endpoints2 = importer.ImportAllEndpoints();

            Assert.That(endpoints2, Is.Not.Null, label.Get());
            Assert.That(endpoints2.Count, Is.EqualTo(0), label.Get());

            label.LeaveScope();
        }
Beispiel #24
0
        public static void NetTcpBinding(
            TestContext context, MetadataSet doc, SecurityMode security,
            bool reliableSession, TransferMode transferMode, TestLabel label)
        {
            label.EnterScope("netTcpBinding");

            var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

            label.EnterScope("wsdl");

            label.EnterScope("extensions");
            Assert.That(sd.Extensions, Is.Not.Null, label.Get());
            Assert.That(sd.Extensions.Count, Is.EqualTo(1), label.Get());
            Assert.That(sd.Extensions [0], Is.InstanceOfType(typeof(XmlElement)), label.Get());

            var extension = (XmlElement)sd.Extensions [0];

            Assert.That(extension.NamespaceURI, Is.EqualTo(WspNamespace), label.Get());
            Assert.That(extension.LocalName, Is.EqualTo("Policy"), label.Get());
            label.LeaveScope();

            label.EnterScope("bindings");
            Assert.That(sd.Bindings.Count, Is.EqualTo(1), label.Get());
            var binding = sd.Bindings [0];

            Assert.That(binding.ExtensibleAttributes, Is.Null, label.Get());
            Assert.That(binding.Extensions, Is.Not.Null, label.Get());

            WS.SoapBinding soap = null;
            XmlElement     xml  = null;

            foreach (var ext in binding.Extensions)
            {
                if (ext is WS.SoapBinding)
                {
                    soap = (WS.SoapBinding)ext;
                }
                else if (ext is XmlElement)
                {
                    xml = (XmlElement)ext;
                }
            }

            CheckSoapBinding(soap, "http://schemas.microsoft.com/soap/tcp", label);

            if (context.CheckPolicyXml)
            {
                label.EnterScope("policy-xml");
                Assert.That(xml, Is.Not.Null, label.Get());

                Assert.That(xml.NamespaceURI, Is.EqualTo(WspNamespace), label.Get());
                Assert.That(xml.LocalName, Is.EqualTo("PolicyReference"), label.Get());
                label.LeaveScope();
            }

            label.LeaveScope();              // wsdl

            var importer = new WsdlImporter(doc);

            label.EnterScope("bindings");
            var bindings = importer.ImportAllBindings();

            CheckImportErrors(importer, label);
            Assert.That(bindings, Is.Not.Null, label.Get());
            Assert.That(bindings.Count, Is.EqualTo(1), label.Get());

            CheckNetTcpBinding(
                bindings [0], security, reliableSession,
                transferMode, label);
            label.LeaveScope();

            label.EnterScope("endpoints");
            var endpoints = importer.ImportAllEndpoints();

            CheckImportErrors(importer, label);
            Assert.That(endpoints, Is.Not.Null, label.Get());
            Assert.That(endpoints.Count, Is.EqualTo(1), label.Get());

            CheckEndpoint(endpoints [0], MetadataSamples.NetTcpUri, label);
            label.LeaveScope();

            label.LeaveScope();
        }
Beispiel #25
0
		public void BasicHttpBinding_Error2 ()
		{
			var label = new TestLabel ("BasicHttpBinding_Error2");
			
			var doc = TestContext.LoadMetadata ("http-error.xml");
			var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;
			
			label.EnterScope ("wsdl");
			Assert.That (sd.Services, Is.Not.Null, label.Get ());
			Assert.That (sd.Services.Count, Is.EqualTo (1), label.Get ());
			
			var service = sd.Services [0];
			Assert.That (service.Ports, Is.Not.Null, label.Get ());
			Assert.That (service.Ports.Count, Is.EqualTo (1), label.Get ());
			label.LeaveScope ();
			
			var importer = new WsdlImporter (doc);
			
			label.EnterScope ("all");
			
			var endpoints = importer.ImportAllEndpoints ();
			Assert.That (endpoints, Is.Not.Null, label.Get ());
			Assert.That (endpoints.Count, Is.EqualTo (0), label.Get ());
			
			label.EnterScope ("errors");
			Assert.That (importer.Errors, Is.Not.Null, label.Get ());
			Assert.That (importer.Errors.Count, Is.EqualTo (2), label.Get ());
			
			Assert.That (importer.Errors [0].IsWarning, Is.False, label.Get ());
			Assert.That (importer.Errors [1].IsWarning, Is.False, label.Get ());
			label.LeaveScope ();
			label.LeaveScope ();
			
			label.EnterScope ("single");
			
			try {
				importer.ImportEndpoint (service.Ports [0]);
				Assert.Fail (label.Get ());
			} catch {
				;
			}
			
			Assert.That (importer.Errors.Count, Is.EqualTo (2), label.Get ());
			
			label.LeaveScope ();
			
			label.EnterScope ("single-first");
			
			var importer2 = new WsdlImporter (doc);
			
			try {
				importer2.ImportEndpoint (service.Ports [0]);
				Assert.Fail (label.Get ());
			} catch {
				;
			}
			
			Assert.That (importer2.Errors.Count, Is.EqualTo (2), label.Get ());
			
			try {
				importer2.ImportEndpoint (service.Ports [0]);
				Assert.Fail (label.Get ());
			} catch {
				;
			}
			
			var endpoints2 = importer.ImportAllEndpoints ();
			Assert.That (endpoints2, Is.Not.Null, label.Get ());
			Assert.That (endpoints2.Count, Is.EqualTo (0), label.Get ());
			
			label.LeaveScope ();
		}
Beispiel #26
0
        public static void BasicHttpBinding(
            TestContext context, MetadataSet doc, BasicHttpSecurityMode security,
            WSMessageEncoding encoding, HttpClientCredentialType clientCred,
            AuthenticationSchemes authScheme, TestLabel label)
        {
            label.EnterScope("basicHttpBinding");

            var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

            label.EnterScope("wsdl");
            label.EnterScope("bindings");
            Assert.That(sd.Bindings.Count, Is.EqualTo(1), label.Get());

            var binding = sd.Bindings [0];

            Assert.That(binding.ExtensibleAttributes, Is.Null, label.Get());
            Assert.That(binding.Extensions, Is.Not.Null, label.Get());

            bool hasPolicyXml;

            switch (security)
            {
            case BasicHttpSecurityMode.None:
                hasPolicyXml = encoding == WSMessageEncoding.Mtom;
                break;

            case BasicHttpSecurityMode.Message:
            case BasicHttpSecurityMode.Transport:
            case BasicHttpSecurityMode.TransportWithMessageCredential:
                if (encoding == WSMessageEncoding.Mtom)
                {
                    throw new InvalidOperationException();
                }
                hasPolicyXml = true;
                break;

            case BasicHttpSecurityMode.TransportCredentialOnly:
                hasPolicyXml = true;
                break;

            default:
                throw new InvalidOperationException();
            }
            label.LeaveScope();

            WS.SoapBinding soap = null;
            XmlElement     xml  = null;

            foreach (var ext in binding.Extensions)
            {
                if (ext is WS.SoapBinding)
                {
                    soap = (WS.SoapBinding)ext;
                }
                else if (ext is XmlElement)
                {
                    xml = (XmlElement)ext;
                }
            }

            CheckSoapBinding(soap, WS.SoapBinding.HttpTransport, label);
            label.LeaveScope();

            label.EnterScope("policy-xml");
            if (!hasPolicyXml)
            {
                Assert.That(xml, Is.Null, label.Get());
            }
            else if (context.CheckPolicyXml)
            {
                Assert.That(xml, Is.Not.Null, label.Get());

                Assert.That(xml.NamespaceURI, Is.EqualTo(WspNamespace), label.Get());
                Assert.That(xml.LocalName, Is.EqualTo("PolicyReference"), label.Get());
            }
            label.LeaveScope();

            var importer = new WsdlImporter(doc);

            label.EnterScope("bindings");
            var bindings = importer.ImportAllBindings();

            CheckImportErrors(importer, label);

            Assert.That(bindings, Is.Not.Null, label.Get());
            Assert.That(bindings.Count, Is.EqualTo(1), label.Get());

            string scheme;

            if ((security == BasicHttpSecurityMode.Transport) ||
                (security == BasicHttpSecurityMode.TransportWithMessageCredential))
            {
                scheme = "https";
            }
            else
            {
                scheme = "http";
            }

            CheckBasicHttpBinding(
                bindings [0], scheme, security, encoding, clientCred,
                authScheme, label);
            label.LeaveScope();

            label.EnterScope("endpoints");
            var endpoints = importer.ImportAllEndpoints();

            CheckImportErrors(importer, label);

            Assert.That(endpoints, Is.Not.Null, label.Get());
            Assert.That(endpoints.Count, Is.EqualTo(1), label.Get());

            CheckEndpoint(endpoints [0], MetadataSamples.HttpUri, label);
            label.LeaveScope();

            label.LeaveScope();
        }
Beispiel #27
0
        public static void CheckExport(
            WS.ServiceDescription wsdl, QName contractName, string bindingName,
            int countEndpoints, TestLabel label)
        {
            label.EnterScope("ServiceDescription");
            Assert.That(wsdl.TargetNamespace, Is.EqualTo(contractName.Namespace), label.Get());
            Assert.That(wsdl.Name, Is.EqualTo("service"), label.Get());
            label.LeaveScope();

            label.EnterScope("Bindings");
            Assert.That(wsdl.Bindings, Is.Not.Null, label.Get());
            Assert.That(wsdl.Bindings.Count, Is.EqualTo(countEndpoints), label.Get());

            for (int i = 0; i < countEndpoints; i++)
            {
                label.EnterScope(string.Format("#{0}", i + 1));
                var binding      = wsdl.Bindings [i];
                var expectedName = string.Format(
                    "{0}_{1}{2}", bindingName, contractName.Name,
                    i > 0 ? i.ToString() : "");
                Assert.That(binding.Name, Is.EqualTo(expectedName), label.Get());
                Assert.That(binding.Type, Is.EqualTo(contractName), label.Get());
                label.LeaveScope();
            }
            label.LeaveScope();

            label.EnterScope("PortTypes");
            Assert.That(wsdl.PortTypes, Is.Not.Null, label.Get());
            Assert.That(wsdl.PortTypes.Count, Is.EqualTo(1), label.Get());
            var portType = wsdl.PortTypes [0];

            Assert.That(portType.Name, Is.EqualTo(contractName.Name), label.Get());
            label.LeaveScope();

            label.EnterScope("Services");
            Assert.That(wsdl.Services, Is.Not.Null, label.Get());
            Assert.That(wsdl.Services.Count, Is.EqualTo(1), label.Get());
            var service = wsdl.Services [0];

            Assert.That(service.Name, Is.EqualTo("service"), label.Get());
            label.LeaveScope();

            label.EnterScope("Ports");
            Assert.That(service.Ports, Is.Not.Null, label.Get());
            Assert.That(service.Ports.Count, Is.EqualTo(countEndpoints), label.Get());
            for (int i = 0; i < countEndpoints; i++)
            {
                label.EnterScope(string.Format("#{0}", i + 1));
                var port         = service.Ports [i];
                var expectedName = string.Format(
                    "{0}_{1}{2}", bindingName, contractName.Name,
                    i > 0 ? i.ToString() : "");
                var qname = new QName(expectedName, contractName.Namespace);
                Assert.That(port.Name, Is.EqualTo(qname.Name), label.Get());
                Assert.That(port.Binding, Is.EqualTo(qname), label.Get());
                label.LeaveScope();
            }
            label.LeaveScope();
        }
Beispiel #28
0
        public void BasicHttpBinding_ImportEndpoints()
        {
            var label = new TestLabel("BasicHttpBinding_ImportEndpoints");

            var doc = TestContext.LoadMetadata("BasicHttp");
            var sd  = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

            label.EnterScope("wsdl");
            Assert.That(sd.Bindings, Is.Not.Null, label.Get());
            Assert.That(sd.Bindings.Count, Is.EqualTo(1), label.Get());
            var binding = sd.Bindings [0];

            Assert.That(sd.Services, Is.Not.Null, label.Get());
            Assert.That(sd.Services.Count, Is.EqualTo(1), label.Get());
            var service = sd.Services [0];

            Assert.That(service.Ports, Is.Not.Null, label.Get());
            Assert.That(service.Ports.Count, Is.EqualTo(1), label.Get());
            var port = service.Ports [0];

            Assert.That(sd.PortTypes, Is.Not.Null, label.Get());
            Assert.That(sd.PortTypes.Count, Is.EqualTo(1), label.Get());
            var portType = sd.PortTypes [0];

            label.LeaveScope();

            var importer = new WsdlImporter(doc);

            label.EnterScope("by-service");
            var byService = importer.ImportEndpoints(service);

            BindingTestAssertions.CheckImportErrors(importer, label);
            Assert.That(byService, Is.Not.Null, label.Get());
            Assert.That(byService.Count, Is.EqualTo(1), label.Get());
            label.LeaveScope();

            label.EnterScope("by-binding");
            var byBinding = importer.ImportEndpoints(binding);

            BindingTestAssertions.CheckImportErrors(importer, label);
            Assert.That(byBinding, Is.Not.Null, label.Get());
            Assert.That(byBinding.Count, Is.EqualTo(1), label.Get());
            label.LeaveScope();

            label.EnterScope("by-port-type");
            var byPortType = importer.ImportEndpoints(portType);

            BindingTestAssertions.CheckImportErrors(importer, label);
            Assert.That(byPortType, Is.Not.Null, label.Get());
            Assert.That(byPortType.Count, Is.EqualTo(1), label.Get());
            label.LeaveScope();
        }
Beispiel #29
0
		static void TestSoapMessage (WS.MessageBinding binding, bool soap12, TestLabel label)
		{
			label.EnterScope (binding is WS.InputBinding ? "input" : "output");

			Assert.That (binding, Is.Not.Null, label.Get ());
			Assert.That (binding.Name, Is.Null, label.Get ());
			Assert.That (binding.ExtensibleAttributes, Is.Null, label.Get ());
			Assert.That (binding.Extensions, Is.Not.Null, label.Get ());
			Assert.That (binding.Extensions.Count, Is.EqualTo (1), label.Get ());
			Assert.That (binding.Extensions [0], Is.InstanceOfType (typeof (WS.SoapBodyBinding)), label.Get ());
			var body = (WS.SoapBodyBinding)binding.Extensions [0];
			TestSoapBody (body, soap12, label);
			label.LeaveScope ();
		}
        public static void CheckNetTcpBinding(
            Binding binding, SecurityMode security, bool reliableSession,
            TransferMode transferMode, TestLabel label)
        {
            label.EnterScope("net-tcp");
            if (security == SecurityMode.Message)
            {
                Assert.That(binding, Is.InstanceOfType(typeof(CustomBinding)), label.Get());
            }
            else
            {
                Assert.That(binding, Is.InstanceOfType(typeof(NetTcpBinding)), label.Get());
                var netTcp = (NetTcpBinding)binding;
                Assert.That(netTcp.EnvelopeVersion, Is.EqualTo(EnvelopeVersion.Soap12), label.Get());
                Assert.That(netTcp.MessageVersion, Is.EqualTo(MessageVersion.Soap12WSAddressing10), label.Get());
                Assert.That(netTcp.Scheme, Is.EqualTo("net.tcp"), label.Get());
                Assert.That(netTcp.TransferMode, Is.EqualTo(transferMode), label.Get());

                label.EnterScope("security");
                Assert.That(netTcp.Security, Is.Not.Null, label.Get());
                Assert.That(netTcp.Security.Mode, Is.EqualTo(security), label.Get());

                Assert.That(netTcp.Security.Transport, Is.Not.Null, label.Get());
                Assert.That(netTcp.Security.Transport.ProtectionLevel, Is.EqualTo(ProtectionLevel.EncryptAndSign), label.Get());
                Assert.That(netTcp.Security.Transport.ClientCredentialType, Is.EqualTo(TcpClientCredentialType.Windows), label.Get());
                label.LeaveScope();
            }

            label.EnterScope("elements");

            var elements = binding.CreateBindingElements();

            Assert.That(elements, Is.Not.Null, label.Get());

            TcpTransportBindingElement          transportElement         = null;
            TransactionFlowBindingElement       transactionFlowElement   = null;
            BinaryMessageEncodingBindingElement encodingElement          = null;
            WindowsStreamSecurityBindingElement windowsStreamElement     = null;
            ReliableSessionBindingElement       reliableSessionElement   = null;
            TransportSecurityBindingElement     transportSecurityElement = null;
            SslStreamSecurityBindingElement     sslStreamElement         = null;
            SymmetricSecurityBindingElement     symmSecurityElement      = null;

            foreach (var element in elements)
            {
                if (element is TcpTransportBindingElement)
                {
                    transportElement = (TcpTransportBindingElement)element;
                }
                else if (element is TransactionFlowBindingElement)
                {
                    transactionFlowElement = (TransactionFlowBindingElement)element;
                }
                else if (element is BinaryMessageEncodingBindingElement)
                {
                    encodingElement = (BinaryMessageEncodingBindingElement)element;
                }
                else if (element is WindowsStreamSecurityBindingElement)
                {
                    windowsStreamElement = (WindowsStreamSecurityBindingElement)element;
                }
                else if (element is ReliableSessionBindingElement)
                {
                    reliableSessionElement = (ReliableSessionBindingElement)element;
                }
                else if (element is TransportSecurityBindingElement)
                {
                    transportSecurityElement = (TransportSecurityBindingElement)element;
                }
                else if (element is SslStreamSecurityBindingElement)
                {
                    sslStreamElement = (SslStreamSecurityBindingElement)element;
                }
                else if (element is SymmetricSecurityBindingElement)
                {
                    symmSecurityElement = (SymmetricSecurityBindingElement)element;
                }
                else
                {
                    Assert.Fail(string.Format(
                                    "Unknown element `{0}'.", element.GetType()), label.Get());
                }
            }

            label.EnterScope("windows-stream");
            if (security == SecurityMode.Transport)
            {
                Assert.That(windowsStreamElement, Is.Not.Null, label.Get());
                Assert.That(windowsStreamElement.ProtectionLevel, Is.EqualTo(ProtectionLevel.EncryptAndSign), label.Get());
            }
            else
            {
                Assert.That(windowsStreamElement, Is.Null, label.Get());
            }
            label.LeaveScope();

            label.EnterScope("reliable-session");
            if (reliableSession)
            {
                Assert.That(reliableSessionElement, Is.Not.Null, label.Get());
            }
            else
            {
                Assert.That(reliableSessionElement, Is.Null, label.Get());
            }
            label.LeaveScope();

            label.EnterScope("encoding");
            Assert.That(encodingElement, Is.Not.Null, label.Get());
            label.LeaveScope();

            label.EnterScope("transaction");
            if (security == SecurityMode.Message)
            {
                Assert.That(transactionFlowElement, Is.Null, label.Get());
            }
            else
            {
                Assert.That(transactionFlowElement, Is.Not.Null, label.Get());
            }
            label.LeaveScope();

            label.EnterScope("transport");
            Assert.That(transportElement, Is.Not.Null, label.Get());

            Assert.That(transportElement.Scheme, Is.EqualTo("net.tcp"), label.Get());
            Assert.That(transportElement.TransferMode, Is.EqualTo(transferMode), label.Get());
            label.LeaveScope();              // transport

            label.EnterScope("security");
            switch (security)
            {
            case SecurityMode.None:
            case SecurityMode.Transport:
                Assert.That(transportSecurityElement, Is.Null, label.Get());
                Assert.That(sslStreamElement, Is.Null, label.Get());
                Assert.That(symmSecurityElement, Is.Null, label.Get());
                break;

            case SecurityMode.TransportWithMessageCredential:
                Assert.That(transportSecurityElement, Is.Not.Null, label.Get());
                Assert.That(sslStreamElement, Is.Not.Null, label.Get());
                Assert.That(symmSecurityElement, Is.Null, label.Get());
                break;

            case SecurityMode.Message:
                Assert.That(transportSecurityElement, Is.Null, label.Get());
                Assert.That(sslStreamElement, Is.Null, label.Get());
                Assert.That(symmSecurityElement, Is.Not.Null, label.Get());
                break;

            default:
                throw new InvalidOperationException();
            }
            label.LeaveScope();

            label.LeaveScope();              // elements
            label.LeaveScope();              // net-tcp
        }
Beispiel #31
0
		static void TestSoapBody (WS.SoapBodyBinding soap, bool soap12, TestLabel label)
		{
			label.EnterScope ("soap-body");
			var type = soap12 ? typeof (WS.Soap12BodyBinding) : typeof (WS.SoapBodyBinding);
			Assert.That (soap.GetType (), Is.EqualTo (type), label.Get ());
			Assert.That (soap.Encoding, Is.Empty, label.Get ());
			Assert.That (soap.Namespace, Is.Empty, label.Get ());
			Assert.That (soap.Parts, Is.Null, label.Get ());
			Assert.That (soap.Use, Is.EqualTo (WS.SoapBindingUse.Literal), label.Get ());
			label.LeaveScope ();
		}
Beispiel #32
0
        public void Mtom_Policy()
        {
            var label    = new TestLabel("Mtom_Policy");
            var contract = new ContractDescription("MyContract");
            var binding  = new BasicHttpBinding();

            binding.MessageEncoding = WSMessageEncoding.Mtom;

            var endpoint = new ServiceEndpoint(
                contract, binding, new EndpointAddress(HttpUri));

            var exporter = new WsdlExporter();

            exporter.ExportEndpoint(endpoint);

            Assert.That(exporter.GeneratedWsdlDocuments, Is.Not.Null, label.Get());
            Assert.That(exporter.GeneratedWsdlDocuments.Count, Is.EqualTo(1), label.Get());
            var wsdl = exporter.GeneratedWsdlDocuments [0];

            Assert.That(wsdl.Bindings, Is.Not.Null, label.Get());
            Assert.That(wsdl.Bindings.Count, Is.EqualTo(1), label.Get());

            var wsb = wsdl.Bindings [0];

            label.EnterScope("Binding");
            Assert.That(wsb.Extensions, Is.Not.Null, label.Get());
            Assert.That(wsb.Extensions.Count, Is.EqualTo(2), label.Get());
            label.LeaveScope();

            label.EnterScope("Extensions");
            WS.SoapBinding soap = null;
            XmlElement     xml  = null;

            foreach (var extension in wsb.Extensions)
            {
                if (extension is WS.SoapBinding)
                {
                    soap = (WS.SoapBinding)extension;
                }
                else if (extension is XmlElement)
                {
                    xml = (XmlElement)extension;
                }
                else
                {
                    Assert.Fail("Unknown extension.", label);
                }
            }

            Assert.That(soap, Is.Not.Null, label.Get());
            Assert.That(xml, Is.Not.Null, label.Get());
            label.LeaveScope();

            label.EnterScope("Policy");
            var assertions = BindingTestAssertions.AssertPolicy(wsdl, xml, label);

            Assert.That(assertions.Count, Is.EqualTo(1), label.Get());
            var assertion = assertions [0];

            Assert.That(assertion.NamespaceURI, Is.EqualTo("http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization"), label.Get());
            Assert.That(assertion.LocalName, Is.EqualTo("OptimizedMimeSerialization"), label.Get());
            label.LeaveScope();
        }
Beispiel #33
0
        public static void BasicHttpsBinding(
            TestContext context, MetadataSet doc, BasicHttpSecurityMode security,
            WSMessageEncoding encoding, HttpClientCredentialType clientCred,
            AuthenticationSchemes authScheme, TestLabel label)
        {
            label.EnterScope("basicHttpsBinding");

            var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

            label.EnterScope("wsdl");

            Assert.That(sd.Extensions, Is.Not.Null, label.Get());
            Assert.That(sd.Extensions.Count, Is.EqualTo(1), label.Get());
            Assert.That(sd.Extensions [0], Is.InstanceOfType(typeof(XmlElement)), label.Get());

            label.EnterScope("extensions");
            var extension = (XmlElement)sd.Extensions [0];

            Assert.That(extension.NamespaceURI, Is.EqualTo(WspNamespace), label.Get());
            Assert.That(extension.LocalName, Is.EqualTo("Policy"), label.Get());
            label.LeaveScope();

            label.EnterScope("bindings");
            Assert.That(sd.Bindings.Count, Is.EqualTo(1), label.Get());
            var binding = sd.Bindings [0];

            Assert.That(binding.ExtensibleAttributes, Is.Null, label.Get());
            Assert.That(binding.Extensions, Is.Not.Null, label.Get());
            label.LeaveScope();

            WS.SoapBinding soap = null;
            XmlElement     xml  = null;

            foreach (var ext in binding.Extensions)
            {
                if (ext is WS.SoapBinding)
                {
                    soap = (WS.SoapBinding)ext;
                }
                else if (ext is XmlElement)
                {
                    xml = (XmlElement)ext;
                }
            }

            CheckSoapBinding(soap, WS.SoapBinding.HttpTransport, label);

            if (context.CheckPolicyXml)
            {
                label.EnterScope("policy-xml");
                Assert.That(xml, Is.Not.Null, label.Get());
                Assert.That(xml.NamespaceURI, Is.EqualTo(WspNamespace), label.Get());
                Assert.That(xml.LocalName, Is.EqualTo("PolicyReference"), label.Get());
                label.LeaveScope();
            }

            label.LeaveScope();              // wsdl

            var importer = new WsdlImporter(doc);

            label.EnterScope("bindings");
            var bindings = importer.ImportAllBindings();

            CheckImportErrors(importer, label);
            Assert.That(bindings, Is.Not.Null, label.Get());
            Assert.That(bindings.Count, Is.EqualTo(1), label.Get());

            CheckBasicHttpBinding(
                bindings [0], "https", security, encoding,
                clientCred, authScheme, label);
            label.LeaveScope();

            label.EnterScope("endpoints");
            var endpoints = importer.ImportAllEndpoints();

            CheckImportErrors(importer, label);
            Assert.That(endpoints, Is.Not.Null, label.Get());
            Assert.That(endpoints.Count, Is.EqualTo(1), label.Get());

            CheckEndpoint(endpoints [0], MetadataSamples.HttpsUri, label);
            label.LeaveScope();

            label.LeaveScope();
        }
Beispiel #34
0
        public void BasicHttpBinding_Error()
        {
            var label = new TestLabel("BasicHttpBinding_Error");

            var doc         = TestContext.LoadMetadata("http-error.xml");
            var sd          = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;
            var wsdlBinding = sd.Bindings [0];

            var importer = new WsdlImporter(doc);

            label.EnterScope("all");

            var bindings = importer.ImportAllBindings();

            Assert.That(bindings, Is.Not.Null, label.Get());
            Assert.That(bindings.Count, Is.EqualTo(0), label.Get());

            label.EnterScope("errors");
            Assert.That(importer.Errors, Is.Not.Null, label.Get());
            Assert.That(importer.Errors.Count, Is.EqualTo(1), label.Get());

            var error = importer.Errors [0];

            Assert.That(error.IsWarning, Is.False, label.Get());
            label.LeaveScope();
            label.LeaveScope();

            label.EnterScope("single");

            try {
                importer.ImportBinding(wsdlBinding);
                Assert.Fail(label.Get());
            } catch {
                ;
            }

            Assert.That(importer.Errors.Count, Is.EqualTo(1), label.Get());

            label.LeaveScope();

            label.EnterScope("single-first");

            var importer2 = new WsdlImporter(doc);

            try {
                importer2.ImportBinding(wsdlBinding);
                Assert.Fail(label.Get());
            } catch {
                ;
            }

            Assert.That(importer2.Errors.Count, Is.EqualTo(1), label.Get());

            try {
                importer2.ImportBinding(wsdlBinding);
                Assert.Fail(label.Get());
            } catch {
                ;
            }

            var bindings2 = importer.ImportAllBindings();

            Assert.That(bindings2, Is.Not.Null, label.Get());
            Assert.That(bindings2.Count, Is.EqualTo(0), label.Get());

            label.LeaveScope();
        }
Beispiel #35
0
		public static void BasicHttpsBinding (
			TestContext context, MetadataSet doc, BasicHttpSecurityMode security,
			WSMessageEncoding encoding, HttpClientCredentialType clientCred,
			AuthenticationSchemes authScheme, TestLabel label)
		{
			label.EnterScope ("basicHttpsBinding");

			var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

			label.EnterScope ("wsdl");

			Assert.That (sd.Extensions, Is.Not.Null, label.Get ());
			Assert.That (sd.Extensions.Count, Is.EqualTo (1), label.Get ());
			Assert.That (sd.Extensions [0], Is.InstanceOfType (typeof(XmlElement)), label.Get ());

			label.EnterScope ("extensions");
			var extension = (XmlElement)sd.Extensions [0];
			Assert.That (extension.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ());
			Assert.That (extension.LocalName, Is.EqualTo ("Policy"), label.Get ());
			label.LeaveScope ();

			label.EnterScope ("bindings");
			Assert.That (sd.Bindings.Count, Is.EqualTo (1), label.Get ());
			var binding = sd.Bindings [0];
			Assert.That (binding.ExtensibleAttributes, Is.Null, label.Get ());
			Assert.That (binding.Extensions, Is.Not.Null, label.Get ());
			label.LeaveScope ();

			WS.SoapBinding soap = null;
			XmlElement xml = null;

			foreach (var ext in binding.Extensions) {
				if (ext is WS.SoapBinding)
					soap = (WS.SoapBinding)ext;
				else if (ext is XmlElement)
					xml = (XmlElement)ext;
			}

			CheckSoapBinding (soap, WS.SoapBinding.HttpTransport, label);

			if (context.CheckPolicyXml) {
				label.EnterScope ("policy-xml");
				Assert.That (xml, Is.Not.Null, label.Get ());
				Assert.That (xml.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ());
				Assert.That (xml.LocalName, Is.EqualTo ("PolicyReference"), label.Get ());
				label.LeaveScope ();
			}

			label.LeaveScope (); // wsdl

			var importer = new WsdlImporter (doc);

			label.EnterScope ("bindings");
			var bindings = importer.ImportAllBindings ();
			CheckImportErrors (importer, label);
			Assert.That (bindings, Is.Not.Null, label.Get ());
			Assert.That (bindings.Count, Is.EqualTo (1), label.Get ());

			CheckBasicHttpBinding (
				bindings [0], "https", security, encoding,
				clientCred, authScheme, label);
			label.LeaveScope ();

			label.EnterScope ("endpoints");
			var endpoints = importer.ImportAllEndpoints ();
			CheckImportErrors (importer, label);
			Assert.That (endpoints, Is.Not.Null, label.Get ());
			Assert.That (endpoints.Count, Is.EqualTo (1), label.Get ());
			
			CheckEndpoint (endpoints [0], MetadataSamples.HttpsUri, label);
			label.LeaveScope ();

			label.LeaveScope ();
		}
Beispiel #36
0
		public static void CheckBasicHttpBinding (
			Binding binding, string scheme, BasicHttpSecurityMode security,
			WSMessageEncoding encoding, HttpClientCredentialType clientCred,
			AuthenticationSchemes authScheme, TestLabel label)
		{
			label.EnterScope ("http");

			if (security == BasicHttpSecurityMode.Message) {
				Assert.That (binding, Is.InstanceOfType (typeof(CustomBinding)), label.Get ());
			} else {
				Assert.That (binding, Is.InstanceOfType (typeof(BasicHttpBinding)), label.Get ());
				var basicHttp = (BasicHttpBinding)binding;
				Assert.That (basicHttp.EnvelopeVersion, Is.EqualTo (EnvelopeVersion.Soap11), label.Get ());
				Assert.That (basicHttp.MessageVersion, Is.EqualTo (MessageVersion.Soap11), label.Get ());
				Assert.That (basicHttp.Scheme, Is.EqualTo (scheme), label.Get ());
				Assert.That (basicHttp.TransferMode, Is.EqualTo (TransferMode.Buffered), label.Get ());
				Assert.That (basicHttp.MessageEncoding, Is.EqualTo (encoding), label.Get ());
				Assert.That (basicHttp.Security, Is.Not.Null, label.Get ());
				Assert.That (basicHttp.Security.Mode, Is.EqualTo (security), label.Get ());
				Assert.That (basicHttp.Security.Transport.ClientCredentialType, Is.EqualTo (clientCred), label.Get ());
				Assert.That (basicHttp.Security.Message.AlgorithmSuite, Is.EqualTo (SecurityAlgorithmSuite.Basic256), label.Get ());
			}

			label.EnterScope ("elements");

			var elements = binding.CreateBindingElements ();
			Assert.That (elements, Is.Not.Null, label.Get ());
			if ((security == BasicHttpSecurityMode.Message) ||
				(security == BasicHttpSecurityMode.TransportWithMessageCredential))
				Assert.That (elements.Count, Is.EqualTo (3), label.Get ());
			else
				Assert.That (elements.Count, Is.EqualTo (2), label.Get ());
			
			TextMessageEncodingBindingElement textElement = null;
			TransportSecurityBindingElement securityElement = null;
			HttpTransportBindingElement transportElement = null;
			AsymmetricSecurityBindingElement asymmSecurityElement = null;
			MtomMessageEncodingBindingElement mtomElement = null;
			
			foreach (var element in elements) {
				if (element is TextMessageEncodingBindingElement)
					textElement = (TextMessageEncodingBindingElement)element;
				else if (element is HttpTransportBindingElement)
					transportElement = (HttpTransportBindingElement)element;
				else if (element is TransportSecurityBindingElement)
					securityElement = (TransportSecurityBindingElement)element;
				else if (element is AsymmetricSecurityBindingElement)
					asymmSecurityElement = (AsymmetricSecurityBindingElement)element;
				else if (element is MtomMessageEncodingBindingElement)
					mtomElement = (MtomMessageEncodingBindingElement)element;
				else
					Assert.Fail (string.Format (
						"Unknown element: {0}", element.GetType ()), label.Get ());
			}

			label.EnterScope ("text");
			if (encoding == WSMessageEncoding.Text) {
				Assert.That (textElement, Is.Not.Null, label.Get ());
				Assert.That (textElement.WriteEncoding, Is.InstanceOfType (typeof(UTF8Encoding)), label.Get ());
			} else {
				Assert.That (textElement, Is.Null, label.Get ());
			}
			label.LeaveScope ();

			label.EnterScope ("mtom");
			if (encoding == WSMessageEncoding.Mtom) {
				Assert.That (mtomElement, Is.Not.Null, label.Get ());
			} else {
				Assert.That (mtomElement, Is.Null, label.Get ());
			}
			label.LeaveScope ();

			label.EnterScope ("security");
			if (security == BasicHttpSecurityMode.TransportWithMessageCredential) {
				Assert.That (securityElement, Is.Not.Null, label.Get ());
				Assert.That (securityElement.SecurityHeaderLayout,
				             Is.EqualTo (SecurityHeaderLayout.Lax), label.Get ());
			} else {
				Assert.That (securityElement, Is.Null, label.Get ());
			}
			label.LeaveScope ();

			label.EnterScope ("asymmetric");
			if (security == BasicHttpSecurityMode.Message) {
				Assert.That (asymmSecurityElement, Is.Not.Null, label.Get ());
			} else {
				Assert.That (asymmSecurityElement, Is.Null, label.Get ());
			}
			label.LeaveScope ();

			label.EnterScope ("transport");
			Assert.That (transportElement, Is.Not.Null, label.Get ());
			
			Assert.That (transportElement.Realm, Is.Empty, label.Get ());
			Assert.That (transportElement.Scheme, Is.EqualTo (scheme), label.Get ());
			Assert.That (transportElement.TransferMode, Is.EqualTo (TransferMode.Buffered), label.Get ());

			label.EnterScope ("auth");
			Assert.That (transportElement.AuthenticationScheme, Is.EqualTo (authScheme), label.Get ());
			label.LeaveScope (); // auth
			label.LeaveScope (); // transport
			label.LeaveScope (); // elements
			label.LeaveScope (); // http
		}
        public static void CheckBasicHttpBinding(
            Binding binding, string scheme, BasicHttpSecurityMode security,
            WSMessageEncoding encoding, HttpClientCredentialType clientCred,
            AuthenticationSchemes authScheme, TestLabel label)
        {
            label.EnterScope("http");

            if (security == BasicHttpSecurityMode.Message)
            {
                Assert.That(binding, Is.InstanceOfType(typeof(CustomBinding)), label.Get());
            }
            else
            {
                Assert.That(binding, Is.InstanceOfType(typeof(BasicHttpBinding)), label.Get());
                var basicHttp = (BasicHttpBinding)binding;
                Assert.That(basicHttp.EnvelopeVersion, Is.EqualTo(EnvelopeVersion.Soap11), label.Get());
                Assert.That(basicHttp.MessageVersion, Is.EqualTo(MessageVersion.Soap11), label.Get());
                Assert.That(basicHttp.Scheme, Is.EqualTo(scheme), label.Get());
                Assert.That(basicHttp.TransferMode, Is.EqualTo(TransferMode.Buffered), label.Get());
                Assert.That(basicHttp.MessageEncoding, Is.EqualTo(encoding), label.Get());
                Assert.That(basicHttp.Security, Is.Not.Null, label.Get());
                Assert.That(basicHttp.Security.Mode, Is.EqualTo(security), label.Get());
                Assert.That(basicHttp.Security.Transport.ClientCredentialType, Is.EqualTo(clientCred), label.Get());
                Assert.That(basicHttp.Security.Message.AlgorithmSuite, Is.EqualTo(SecurityAlgorithmSuite.Basic256), label.Get());
            }

            label.EnterScope("elements");

            var elements = binding.CreateBindingElements();

            Assert.That(elements, Is.Not.Null, label.Get());
            if ((security == BasicHttpSecurityMode.Message) ||
                (security == BasicHttpSecurityMode.TransportWithMessageCredential))
            {
                Assert.That(elements.Count, Is.EqualTo(3), label.Get());
            }
            else
            {
                Assert.That(elements.Count, Is.EqualTo(2), label.Get());
            }

            TextMessageEncodingBindingElement textElement          = null;
            TransportSecurityBindingElement   securityElement      = null;
            HttpTransportBindingElement       transportElement     = null;
            AsymmetricSecurityBindingElement  asymmSecurityElement = null;
            MtomMessageEncodingBindingElement mtomElement          = null;

            foreach (var element in elements)
            {
                if (element is TextMessageEncodingBindingElement)
                {
                    textElement = (TextMessageEncodingBindingElement)element;
                }
                else if (element is HttpTransportBindingElement)
                {
                    transportElement = (HttpTransportBindingElement)element;
                }
                else if (element is TransportSecurityBindingElement)
                {
                    securityElement = (TransportSecurityBindingElement)element;
                }
                else if (element is AsymmetricSecurityBindingElement)
                {
                    asymmSecurityElement = (AsymmetricSecurityBindingElement)element;
                }
                else if (element is MtomMessageEncodingBindingElement)
                {
                    mtomElement = (MtomMessageEncodingBindingElement)element;
                }
                else
                {
                    Assert.Fail(string.Format(
                                    "Unknown element: {0}", element.GetType()), label.Get());
                }
            }

            label.EnterScope("text");
            if (encoding == WSMessageEncoding.Text)
            {
                Assert.That(textElement, Is.Not.Null, label.Get());
                Assert.That(textElement.WriteEncoding, Is.InstanceOfType(typeof(UTF8Encoding)), label.Get());
            }
            else
            {
                Assert.That(textElement, Is.Null, label.Get());
            }
            label.LeaveScope();

            label.EnterScope("mtom");
            if (encoding == WSMessageEncoding.Mtom)
            {
                Assert.That(mtomElement, Is.Not.Null, label.Get());
            }
            else
            {
                Assert.That(mtomElement, Is.Null, label.Get());
            }
            label.LeaveScope();

            label.EnterScope("security");
            if (security == BasicHttpSecurityMode.TransportWithMessageCredential)
            {
                Assert.That(securityElement, Is.Not.Null, label.Get());
                Assert.That(securityElement.SecurityHeaderLayout,
                            Is.EqualTo(SecurityHeaderLayout.Lax), label.Get());
            }
            else
            {
                Assert.That(securityElement, Is.Null, label.Get());
            }
            label.LeaveScope();

            label.EnterScope("asymmetric");
            if (security == BasicHttpSecurityMode.Message)
            {
                Assert.That(asymmSecurityElement, Is.Not.Null, label.Get());
            }
            else
            {
                Assert.That(asymmSecurityElement, Is.Null, label.Get());
            }
            label.LeaveScope();

            label.EnterScope("transport");
            Assert.That(transportElement, Is.Not.Null, label.Get());

            Assert.That(transportElement.Realm, Is.Empty, label.Get());
            Assert.That(transportElement.Scheme, Is.EqualTo(scheme), label.Get());
            Assert.That(transportElement.TransferMode, Is.EqualTo(TransferMode.Buffered), label.Get());

            label.EnterScope("auth");
            Assert.That(transportElement.AuthenticationScheme, Is.EqualTo(authScheme), label.Get());
            label.LeaveScope();              // auth
            label.LeaveScope();              // transport
            label.LeaveScope();              // elements
            label.LeaveScope();              // http
        }
Beispiel #38
0
		static void CheckEndpoint (ServiceEndpoint endpoint, string uri, TestLabel label)
		{
			label.EnterScope ("endpoint");
			Assert.That (endpoint.ListenUri, Is.EqualTo (new Uri (uri)), label.Get ());
			Assert.That (endpoint.ListenUriMode, Is.EqualTo (ListenUriMode.Explicit), label.Get ());
			Assert.That (endpoint.Contract, Is.Not.Null, label.Get ());
			Assert.That (endpoint.Contract.Name, Is.EqualTo ("MyContract"), label.Get ());
			Assert.That (endpoint.Address, Is.Not.Null, label.Get ());
			Assert.That (endpoint.Address.Uri, Is.EqualTo (new Uri (uri)), label.Get ());
			Assert.That (endpoint.Address.Identity, Is.Null, label.Get ());
			Assert.That (endpoint.Address.Headers, Is.Not.Null, label.Get ());
			Assert.That (endpoint.Address.Headers.Count, Is.EqualTo (0), label.Get ());
			label.LeaveScope ();
		}
        static void BasicHttpBinding_inner(
            TestContext context, MetadataSet doc, BasicHttpSecurityMode security,
            WSMessageEncoding encoding, HttpClientCredentialType clientCred,
            AuthenticationSchemes authScheme, bool isHttps, TestLabel label)
        {
            var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

            label.EnterScope("wsdl");
            label.EnterScope("bindings");
            Assert.That(sd.Bindings.Count, Is.EqualTo(1), label.Get());

            var binding = sd.Bindings [0];

            Assert.That(binding.ExtensibleAttributes, Is.Null, label.Get());
            Assert.That(binding.Extensions, Is.Not.Null, label.Get());

            bool hasPolicyXml;

            switch (security)
            {
            case BasicHttpSecurityMode.None:
                if (isHttps)
                {
                    throw new InvalidOperationException();
                }
                hasPolicyXml = encoding == WSMessageEncoding.Mtom;
                break;

            case BasicHttpSecurityMode.Message:
            case BasicHttpSecurityMode.Transport:
            case BasicHttpSecurityMode.TransportWithMessageCredential:
                if (encoding == WSMessageEncoding.Mtom)
                {
                    throw new InvalidOperationException();
                }
                hasPolicyXml = true;
                break;

            case BasicHttpSecurityMode.TransportCredentialOnly:
                if (isHttps)
                {
                    throw new InvalidOperationException();
                }
                hasPolicyXml = true;
                break;

            default:
                throw new InvalidOperationException();
            }
            label.LeaveScope();

            WS.SoapBinding soap = null;
            XmlElement     xml  = null;

            foreach (var ext in binding.Extensions)
            {
                if (ext is WS.SoapBinding)
                {
                    soap = (WS.SoapBinding)ext;
                }
                else if (ext is XmlElement)
                {
                    xml = (XmlElement)ext;
                }
            }

            CheckSoapBinding(soap, WS.SoapBinding.HttpTransport, label);
            label.LeaveScope();

            label.EnterScope("policy-xml");
            if (!hasPolicyXml)
            {
                Assert.That(xml, Is.Null, label.Get());
            }
            else
            {
                Assert.That(xml, Is.Not.Null, label.Get());
                var assertions = AssertPolicy(sd, xml, label);
                Assert.That(assertions, Is.Not.Null, label.Get());
                if (clientCred == HttpClientCredentialType.Ntlm)
                {
                    AssertPolicy(assertions, NtlmAuthenticationQName, label);
                }
                if (encoding == WSMessageEncoding.Mtom)
                {
                    AssertPolicy(assertions, MtomEncodingQName, label);
                }
                switch (security)
                {
                case BasicHttpSecurityMode.Message:
                    AssertPolicy(assertions, AsymmetricBindingQName, label);
                    AssertPolicy(assertions, Wss10QName, label);
                    break;

                case BasicHttpSecurityMode.Transport:
                    AssertPolicy(assertions, TransportBindingQName, label);
                    break;

                case BasicHttpSecurityMode.TransportWithMessageCredential:
                    AssertPolicy(assertions, SignedSupportingQName, label);
                    AssertPolicy(assertions, TransportBindingQName, label);
                    AssertPolicy(assertions, Wss10QName, label);
                    break;

                default:
                    break;
                }
                Assert.That(assertions.Count, Is.EqualTo(0), label.Get());
            }
            label.LeaveScope();

            label.EnterScope("services");
            Assert.That(sd.Services, Is.Not.Null, label.Get());
            Assert.That(sd.Services.Count, Is.EqualTo(1), label.Get());
            var service = sd.Services [0];

            Assert.That(service.Ports, Is.Not.Null, label.Get());
            Assert.That(service.Ports.Count, Is.EqualTo(1), label.Get());
            var port = service.Ports [0];

            label.EnterScope("port");
            Assert.That(port.Extensions, Is.Not.Null, label.Get());
            Assert.That(port.Extensions.Count, Is.EqualTo(1), label.Get());

            WS.SoapAddressBinding soap_addr_binding = null;
            foreach (var extension in port.Extensions)
            {
                if (extension is WS.SoapAddressBinding)
                {
                    soap_addr_binding = (WS.SoapAddressBinding)extension;
                }
                else
                {
                    Assert.Fail(label.Get());
                }
            }
            Assert.That(soap_addr_binding, Is.Not.Null, label.Get());
            label.LeaveScope();

            label.LeaveScope();              // wsdl

            var importer = new WsdlImporter(doc);

            label.EnterScope("bindings");
            var bindings = importer.ImportAllBindings();

            CheckImportErrors(importer, label);

            Assert.That(bindings, Is.Not.Null, label.Get());
            Assert.That(bindings.Count, Is.EqualTo(1), label.Get());

            string scheme;

            if ((security == BasicHttpSecurityMode.Transport) ||
                (security == BasicHttpSecurityMode.TransportWithMessageCredential))
            {
                scheme = "https";
            }
            else
            {
                scheme = "http";
            }

            CheckBasicHttpBinding(
                bindings [0], scheme, security, encoding, clientCred,
                authScheme, label);
            label.LeaveScope();

            label.EnterScope("endpoints");
            var endpoints = importer.ImportAllEndpoints();

            CheckImportErrors(importer, label);

            Assert.That(endpoints, Is.Not.Null, label.Get());
            Assert.That(endpoints.Count, Is.EqualTo(1), label.Get());

            var uri = isHttps ? MetadataSamples.HttpsUri : MetadataSamples.HttpUri;

            CheckEndpoint(endpoints [0], uri, label);
            label.LeaveScope();
        }
Beispiel #40
0
		public static void NetTcpBinding (
			TestContext context, MetadataSet doc, SecurityMode security,
			bool reliableSession, TransferMode transferMode, TestLabel label)
		{
			label.EnterScope ("netTcpBinding");

			var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

			label.EnterScope ("wsdl");

			label.EnterScope ("extensions");
			Assert.That (sd.Extensions, Is.Not.Null, label.Get ());
			Assert.That (sd.Extensions.Count, Is.EqualTo (1), label.Get ());
			Assert.That (sd.Extensions [0], Is.InstanceOfType (typeof(XmlElement)), label.Get ());
			
			var extension = (XmlElement)sd.Extensions [0];
			Assert.That (extension.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ());
			Assert.That (extension.LocalName, Is.EqualTo ("Policy"), label.Get ());
			label.LeaveScope ();

			label.EnterScope ("bindings");
			Assert.That (sd.Bindings.Count, Is.EqualTo (1), label.Get ());
			var binding = sd.Bindings [0];
			Assert.That (binding.ExtensibleAttributes, Is.Null, label.Get ());
			Assert.That (binding.Extensions, Is.Not.Null, label.Get ());

			WS.SoapBinding soap = null;
			XmlElement xml = null;
			
			foreach (var ext in binding.Extensions) {
				if (ext is WS.SoapBinding)
					soap = (WS.SoapBinding)ext;
				else if (ext is XmlElement)
					xml = (XmlElement)ext;
			}
			
			CheckSoapBinding (soap, "http://schemas.microsoft.com/soap/tcp", label);

			if (context.CheckPolicyXml) {
				label.EnterScope ("policy-xml");
				Assert.That (xml, Is.Not.Null, label.Get ());
			
				Assert.That (xml.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ());
				Assert.That (xml.LocalName, Is.EqualTo ("PolicyReference"), label.Get ());
				label.LeaveScope ();
			}

			label.LeaveScope (); // wsdl

			var importer = new WsdlImporter (doc);

			label.EnterScope ("bindings");
			var bindings = importer.ImportAllBindings ();
			CheckImportErrors (importer, label);
			Assert.That (bindings, Is.Not.Null, label.Get ());
			Assert.That (bindings.Count, Is.EqualTo (1), label.Get ());
			
			CheckNetTcpBinding (
				bindings [0], security, reliableSession,
				transferMode, label);
			label.LeaveScope ();

			label.EnterScope ("endpoints");
			var endpoints = importer.ImportAllEndpoints ();
			CheckImportErrors (importer, label);
			Assert.That (endpoints, Is.Not.Null, label.Get ());
			Assert.That (endpoints.Count, Is.EqualTo (1), label.Get ());
			
			CheckEndpoint (endpoints [0], MetadataSamples.NetTcpUri, label);
			label.LeaveScope ();

			label.LeaveScope ();
		}
        public static void NetTcpBinding(
            TestContext context, MetadataSet doc, SecurityMode security,
            bool reliableSession, TransferMode transferMode, TestLabel label)
        {
            label.EnterScope("netTcpBinding");

            var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

            label.EnterScope("wsdl");

            label.EnterScope("bindings");
            Assert.That(sd.Bindings.Count, Is.EqualTo(1), label.Get());
            var binding = sd.Bindings [0];

            Assert.That(binding.ExtensibleAttributes, Is.Null, label.Get());
            Assert.That(binding.Extensions, Is.Not.Null, label.Get());

            WS.Soap12Binding soap = null;
            XmlElement       xml  = null;

            foreach (var ext in binding.Extensions)
            {
                if (ext is WS.Soap12Binding)
                {
                    soap = (WS.Soap12Binding)ext;
                }
                else if (ext is XmlElement)
                {
                    xml = (XmlElement)ext;
                }
            }

            CheckSoapBinding(soap, "http://schemas.microsoft.com/soap/tcp", label);

            label.EnterScope("policy-xml");
            Assert.That(xml, Is.Not.Null, label.Get());
            var assertions = AssertPolicy(sd, xml, label);

            Assert.That(assertions, Is.Not.Null, label.Get());
            AssertPolicy(assertions, BinaryEncodingQName, label);
            AssertPolicy(assertions, UsingAddressingQName, label);
            if (transferMode == TransferMode.Streamed)
            {
                AssertPolicy(assertions, StreamedTransferQName, label);
            }
            switch (security)
            {
            case SecurityMode.Message:
                AssertPolicy(assertions, SymmetricBindingQName, label);
                AssertPolicy(assertions, Wss11QName, label);
                AssertPolicy(assertions, Trust10QName, label);
                break;

            case SecurityMode.Transport:
                AssertPolicy(assertions, TransportBindingQName, label);
                break;

            case SecurityMode.TransportWithMessageCredential:
                AssertPolicy(assertions, TransportBindingQName, label);
                AssertPolicy(assertions, EndorsingSupportingQName, label);
                AssertPolicy(assertions, Wss11QName, label);
                AssertPolicy(assertions, Trust10QName, label);
                break;

            default:
                break;
            }
            if (reliableSession)
            {
                AssertPolicy(assertions, ReliableSessionQName, label);
            }
            Assert.That(assertions.Count, Is.EqualTo(0), label.Get());
            label.LeaveScope();

            label.EnterScope("services");
            Assert.That(sd.Services, Is.Not.Null, label.Get());
            Assert.That(sd.Services.Count, Is.EqualTo(1), label.Get());
            var service = sd.Services [0];

            Assert.That(service.Ports, Is.Not.Null, label.Get());
            Assert.That(service.Ports.Count, Is.EqualTo(1), label.Get());
            var port = service.Ports [0];

            label.EnterScope("port");
            Assert.That(port.Extensions, Is.Not.Null, label.Get());
            Assert.That(port.Extensions.Count, Is.EqualTo(2), label.Get());

            WS.Soap12AddressBinding soap_addr_binding = null;
            XmlElement port_xml = null;

            foreach (var extension in port.Extensions)
            {
                if (extension is WS.Soap12AddressBinding)
                {
                    soap_addr_binding = (WS.Soap12AddressBinding)extension;
                }
                else if (extension is XmlElement)
                {
                    port_xml = (XmlElement)extension;
                }
                else
                {
                    Assert.Fail(label.Get());
                }
            }
            Assert.That(soap_addr_binding, Is.Not.Null, label.Get());
            Assert.That(port_xml, Is.Not.Null, label.Get());
            Assert.That(port_xml.NamespaceURI, Is.EqualTo(Wsa10Namespace), label.Get());
            Assert.That(port_xml.LocalName, Is.EqualTo("EndpointReference"), label.Get());
            label.LeaveScope();
            label.LeaveScope();

            label.LeaveScope();              // wsdl

            var importer = new WsdlImporter(doc);

            label.EnterScope("bindings");
            var bindings = importer.ImportAllBindings();

            CheckImportErrors(importer, label);
            Assert.That(bindings, Is.Not.Null, label.Get());
            Assert.That(bindings.Count, Is.EqualTo(1), label.Get());

            CheckNetTcpBinding(
                bindings [0], security, reliableSession,
                transferMode, label);
            label.LeaveScope();

            label.EnterScope("endpoints");
            var endpoints = importer.ImportAllEndpoints();

            CheckImportErrors(importer, label);
            Assert.That(endpoints, Is.Not.Null, label.Get());
            Assert.That(endpoints.Count, Is.EqualTo(1), label.Get());

            CheckEndpoint(endpoints [0], MetadataSamples.NetTcpUri, label);
            label.LeaveScope();

            label.LeaveScope();
        }
Beispiel #42
0
		public static void BasicHttpBinding (
			TestContext context, MetadataSet doc, BasicHttpSecurityMode security,
			WSMessageEncoding encoding, HttpClientCredentialType clientCred,
			AuthenticationSchemes authScheme, TestLabel label)
		{
			label.EnterScope ("basicHttpBinding");

			var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

			label.EnterScope ("wsdl");
			label.EnterScope ("bindings");
			Assert.That (sd.Bindings.Count, Is.EqualTo (1), label.Get ());

			var binding = sd.Bindings [0];
			Assert.That (binding.ExtensibleAttributes, Is.Null, label.Get ());
			Assert.That (binding.Extensions, Is.Not.Null, label.Get ());

			bool hasPolicyXml;

			switch (security) {
			case BasicHttpSecurityMode.None:
				hasPolicyXml = encoding == WSMessageEncoding.Mtom;
				break;
			case BasicHttpSecurityMode.Message:
			case BasicHttpSecurityMode.Transport:
			case BasicHttpSecurityMode.TransportWithMessageCredential:
				if (encoding == WSMessageEncoding.Mtom)
					throw new InvalidOperationException ();
				hasPolicyXml = true;
				break;
			case BasicHttpSecurityMode.TransportCredentialOnly:
				hasPolicyXml = true;
				break;
			default:
				throw new InvalidOperationException ();
			}
			label.LeaveScope ();

			WS.SoapBinding soap = null;
			XmlElement xml = null;

			foreach (var ext in binding.Extensions) {
				if (ext is WS.SoapBinding)
					soap = (WS.SoapBinding)ext;
				else if (ext is XmlElement)
					xml = (XmlElement)ext;
			}

			CheckSoapBinding (soap, WS.SoapBinding.HttpTransport, label);
			label.LeaveScope ();

			label.EnterScope ("policy-xml");
			if (!hasPolicyXml)
				Assert.That (xml, Is.Null, label.Get ());
			else if (context.CheckPolicyXml) {
				Assert.That (xml, Is.Not.Null, label.Get ());
				
				Assert.That (xml.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ());
				Assert.That (xml.LocalName, Is.EqualTo ("PolicyReference"), label.Get ());
			}
			label.LeaveScope ();

			var importer = new WsdlImporter (doc);

			label.EnterScope ("bindings");
			var bindings = importer.ImportAllBindings ();
			CheckImportErrors (importer, label);

			Assert.That (bindings, Is.Not.Null, label.Get ());
			Assert.That (bindings.Count, Is.EqualTo (1), label.Get ());

			string scheme;
			if ((security == BasicHttpSecurityMode.Transport) ||
			    (security == BasicHttpSecurityMode.TransportWithMessageCredential))
				scheme = "https";
			else
				scheme = "http";

			CheckBasicHttpBinding (
				bindings [0], scheme, security, encoding, clientCred,
				authScheme, label);
			label.LeaveScope ();

			label.EnterScope ("endpoints");
			var endpoints = importer.ImportAllEndpoints ();
			CheckImportErrors (importer, label);

			Assert.That (endpoints, Is.Not.Null, label.Get ());
			Assert.That (endpoints.Count, Is.EqualTo (1), label.Get ());

			CheckEndpoint (endpoints [0], MetadataSamples.HttpUri, label);
			label.LeaveScope ();

			label.LeaveScope ();
		}
Beispiel #43
0
		public static void NetTcpBinding (
			TestContext context, MetadataSet doc, SecurityMode security,
			bool reliableSession, TransferMode transferMode, TestLabel label)
		{
			label.EnterScope ("netTcpBinding");

			var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

			label.EnterScope ("wsdl");

			label.EnterScope ("bindings");
			Assert.That (sd.Bindings.Count, Is.EqualTo (1), label.Get ());
			var binding = sd.Bindings [0];
			Assert.That (binding.ExtensibleAttributes, Is.Null, label.Get ());
			Assert.That (binding.Extensions, Is.Not.Null, label.Get ());

			WS.Soap12Binding soap = null;
			XmlElement xml = null;
			
			foreach (var ext in binding.Extensions) {
				if (ext is WS.Soap12Binding)
					soap = (WS.Soap12Binding)ext;
				else if (ext is XmlElement)
					xml = (XmlElement)ext;
			}
			
			CheckSoapBinding (soap, "http://schemas.microsoft.com/soap/tcp", label);

			label.EnterScope ("policy-xml");
			Assert.That (xml, Is.Not.Null, label.Get ());
			var assertions = AssertPolicy (sd, xml, label);
			Assert.That (assertions, Is.Not.Null, label.Get ());
			AssertPolicy (assertions, BinaryEncodingQName, label);
			AssertPolicy (assertions, UsingAddressingQName, label);
			if (transferMode == TransferMode.Streamed)
				AssertPolicy (assertions, StreamedTransferQName, label);
			switch (security) {
			case SecurityMode.Message:
				AssertPolicy (assertions, SymmetricBindingQName, label);
				AssertPolicy (assertions, Wss11QName, label);
				AssertPolicy (assertions, Trust10QName, label);
				break;
			case SecurityMode.Transport:
				AssertPolicy (assertions, TransportBindingQName, label);
				break;
			case SecurityMode.TransportWithMessageCredential:
				AssertPolicy (assertions, TransportBindingQName, label);
				AssertPolicy (assertions, EndorsingSupportingQName, label);
				AssertPolicy (assertions, Wss11QName, label);
				AssertPolicy (assertions, Trust10QName, label);
				break;
			default:
				break;
			}
			if (reliableSession)
				AssertPolicy (assertions, ReliableSessionQName, label);
			Assert.That (assertions.Count, Is.EqualTo (0), label.Get ());
			label.LeaveScope ();

			label.EnterScope ("services");
			Assert.That (sd.Services, Is.Not.Null, label.Get ());
			Assert.That (sd.Services.Count, Is.EqualTo (1), label.Get ());
			var service = sd.Services [0];
			Assert.That (service.Ports, Is.Not.Null, label.Get ());
			Assert.That (service.Ports.Count, Is.EqualTo (1), label.Get ());
			var port = service.Ports [0];

			label.EnterScope ("port");
			Assert.That (port.Extensions, Is.Not.Null, label.Get ());
			Assert.That (port.Extensions.Count, Is.EqualTo (2), label.Get ());

			WS.Soap12AddressBinding soap_addr_binding = null;
			XmlElement port_xml = null;
			foreach (var extension in port.Extensions) {
				if (extension is WS.Soap12AddressBinding)
					soap_addr_binding = (WS.Soap12AddressBinding)extension;
				else if (extension is XmlElement)
					port_xml = (XmlElement)extension;
				else
					Assert.Fail (label.Get ());
			}
			Assert.That (soap_addr_binding, Is.Not.Null, label.Get ());
			Assert.That (port_xml, Is.Not.Null, label.Get ());
			Assert.That (port_xml.NamespaceURI, Is.EqualTo (Wsa10Namespace), label.Get ());
			Assert.That (port_xml.LocalName, Is.EqualTo ("EndpointReference"), label.Get ());
			label.LeaveScope ();
			label.LeaveScope ();

			label.LeaveScope (); // wsdl

			var importer = new WsdlImporter (doc);

			label.EnterScope ("bindings");
			var bindings = importer.ImportAllBindings ();
			CheckImportErrors (importer, label);
			Assert.That (bindings, Is.Not.Null, label.Get ());
			Assert.That (bindings.Count, Is.EqualTo (1), label.Get ());
			
			CheckNetTcpBinding (
				bindings [0], security, reliableSession,
				transferMode, label);
			label.LeaveScope ();

			label.EnterScope ("endpoints");
			var endpoints = importer.ImportAllEndpoints ();
			CheckImportErrors (importer, label);
			Assert.That (endpoints, Is.Not.Null, label.Get ());
			Assert.That (endpoints.Count, Is.EqualTo (1), label.Get ());
			
			CheckEndpoint (endpoints [0], MetadataSamples.NetTcpUri, label);
			label.LeaveScope ();

			label.LeaveScope ();
		}
Beispiel #44
0
		public static PolicyAssertionCollection AssertPolicy (
			WS.Binding binding, TestLabel label)
		{
			label.EnterScope ("FindPolicy");
			XmlElement policy = null;
		
			foreach (var extension in binding.Extensions) {
				var xml = extension as XmlElement;
				if (xml == null)
					continue;
				Assert.That (policy, Is.Null, label.Get ());
				policy = xml;
			}
			Assert.That (policy, Is.Not.Null, label.Get ());
			try {
				return AssertPolicy (binding.ServiceDescription, policy, label);
			} finally {
				label.LeaveScope ();
			}
		}
Beispiel #45
0
		static void BasicHttpBinding_inner (
			TestContext context, MetadataSet doc, BasicHttpSecurityMode security,
			WSMessageEncoding encoding, HttpClientCredentialType clientCred,
			AuthenticationSchemes authScheme, bool isHttps, TestLabel label)
		{
			var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

			label.EnterScope ("wsdl");
			label.EnterScope ("bindings");
			Assert.That (sd.Bindings.Count, Is.EqualTo (1), label.Get ());

			var binding = sd.Bindings [0];
			Assert.That (binding.ExtensibleAttributes, Is.Null, label.Get ());
			Assert.That (binding.Extensions, Is.Not.Null, label.Get ());

			bool hasPolicyXml;

			switch (security) {
			case BasicHttpSecurityMode.None:
				if (isHttps)
					throw new InvalidOperationException ();
				hasPolicyXml = encoding == WSMessageEncoding.Mtom;
				break;
			case BasicHttpSecurityMode.Message:
			case BasicHttpSecurityMode.Transport:
			case BasicHttpSecurityMode.TransportWithMessageCredential:
				if (encoding == WSMessageEncoding.Mtom)
					throw new InvalidOperationException ();
				hasPolicyXml = true;
				break;
			case BasicHttpSecurityMode.TransportCredentialOnly:
				if (isHttps)
					throw new InvalidOperationException ();
				hasPolicyXml = true;
				break;
			default:
				throw new InvalidOperationException ();
			}
			label.LeaveScope ();

			WS.SoapBinding soap = null;
			XmlElement xml = null;

			foreach (var ext in binding.Extensions) {
				if (ext is WS.SoapBinding)
					soap = (WS.SoapBinding)ext;
				else if (ext is XmlElement)
					xml = (XmlElement)ext;
			}

			CheckSoapBinding (soap, WS.SoapBinding.HttpTransport, label);
			label.LeaveScope ();

			label.EnterScope ("policy-xml");
			if (!hasPolicyXml)
				Assert.That (xml, Is.Null, label.Get ());
			else {
				Assert.That (xml, Is.Not.Null, label.Get ());
				var assertions = AssertPolicy (sd, xml, label);
				Assert.That (assertions, Is.Not.Null, label.Get ());
				if (clientCred == HttpClientCredentialType.Ntlm)
					AssertPolicy (assertions, NtlmAuthenticationQName, label);
				if (encoding == WSMessageEncoding.Mtom)
					AssertPolicy (assertions, MtomEncodingQName, label);
				switch (security) {
				case BasicHttpSecurityMode.Message:
					AssertPolicy (assertions, AsymmetricBindingQName, label);
					AssertPolicy (assertions, Wss10QName, label);
					break;
				case BasicHttpSecurityMode.Transport:
					AssertPolicy (assertions, TransportBindingQName, label);
					break;
				case BasicHttpSecurityMode.TransportWithMessageCredential:
					AssertPolicy (assertions, SignedSupportingQName, label);
					AssertPolicy (assertions, TransportBindingQName, label);
					AssertPolicy (assertions, Wss10QName, label);
					break;
				default:
					break;
				}
				Assert.That (assertions.Count, Is.EqualTo (0), label.Get ());
			}
			label.LeaveScope ();

			label.EnterScope ("services");
			Assert.That (sd.Services, Is.Not.Null, label.Get ());
			Assert.That (sd.Services.Count, Is.EqualTo (1), label.Get ());
			var service = sd.Services [0];
			Assert.That (service.Ports, Is.Not.Null, label.Get ());
			Assert.That (service.Ports.Count, Is.EqualTo (1), label.Get ());
			var port = service.Ports [0];
			
			label.EnterScope ("port");
			Assert.That (port.Extensions, Is.Not.Null, label.Get ());
			Assert.That (port.Extensions.Count, Is.EqualTo (1), label.Get ());
			
			WS.SoapAddressBinding soap_addr_binding = null;
			foreach (var extension in port.Extensions) {
				if (extension is WS.SoapAddressBinding)
					soap_addr_binding = (WS.SoapAddressBinding)extension;
				else
					Assert.Fail (label.Get ());
			}
			Assert.That (soap_addr_binding, Is.Not.Null, label.Get ());
			label.LeaveScope ();

			label.LeaveScope (); // wsdl

			var importer = new WsdlImporter (doc);

			label.EnterScope ("bindings");
			var bindings = importer.ImportAllBindings ();
			CheckImportErrors (importer, label);

			Assert.That (bindings, Is.Not.Null, label.Get ());
			Assert.That (bindings.Count, Is.EqualTo (1), label.Get ());

			string scheme;
			if ((security == BasicHttpSecurityMode.Transport) ||
			    (security == BasicHttpSecurityMode.TransportWithMessageCredential))
				scheme = "https";
			else
				scheme = "http";

			CheckBasicHttpBinding (
				bindings [0], scheme, security, encoding, clientCred,
				authScheme, label);
			label.LeaveScope ();

			label.EnterScope ("endpoints");
			var endpoints = importer.ImportAllEndpoints ();
			CheckImportErrors (importer, label);

			Assert.That (endpoints, Is.Not.Null, label.Get ());
			Assert.That (endpoints.Count, Is.EqualTo (1), label.Get ());

			var uri = isHttps ? MetadataSamples.HttpsUri : MetadataSamples.HttpUri;

			CheckEndpoint (endpoints [0], uri, label);
			label.LeaveScope ();
		}
Beispiel #46
0
		public void BasicHttpBinding_ImportEndpoints ()
		{
			var label = new TestLabel ("BasicHttpBinding_ImportEndpoints");
			
			var doc = TestContext.LoadMetadata ("BasicHttp");
			var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;
			
			label.EnterScope ("wsdl");
			Assert.That (sd.Bindings, Is.Not.Null, label.Get ());
			Assert.That (sd.Bindings.Count, Is.EqualTo (1), label.Get ());
			var binding = sd.Bindings [0];
			
			Assert.That (sd.Services, Is.Not.Null, label.Get ());
			Assert.That (sd.Services.Count, Is.EqualTo (1), label.Get ());
			var service = sd.Services [0];
			
			Assert.That (service.Ports, Is.Not.Null, label.Get ());
			Assert.That (service.Ports.Count, Is.EqualTo (1), label.Get ());
			var port = service.Ports [0];
			
			Assert.That (sd.PortTypes, Is.Not.Null, label.Get ());
			Assert.That (sd.PortTypes.Count, Is.EqualTo (1), label.Get ());
			var portType = sd.PortTypes [0];
			
			label.LeaveScope ();
			
			var importer = new WsdlImporter (doc);
			
			label.EnterScope ("by-service");
			var byService = importer.ImportEndpoints (service);
			BindingTestAssertions.CheckImportErrors (importer, label);
			Assert.That (byService, Is.Not.Null, label.Get ());
			Assert.That (byService.Count, Is.EqualTo (1), label.Get ());
			label.LeaveScope ();
			
			label.EnterScope ("by-binding");
			var byBinding = importer.ImportEndpoints (binding);
			BindingTestAssertions.CheckImportErrors (importer, label);
			Assert.That (byBinding, Is.Not.Null, label.Get ());
			Assert.That (byBinding.Count, Is.EqualTo (1), label.Get ());
			label.LeaveScope ();
			
			label.EnterScope ("by-port-type");
			var byPortType = importer.ImportEndpoints (portType);
			BindingTestAssertions.CheckImportErrors (importer, label);
			Assert.That (byPortType, Is.Not.Null, label.Get ());
			Assert.That (byPortType.Count, Is.EqualTo (1), label.Get ());
			label.LeaveScope ();
		}
Beispiel #47
0
		public static void CheckNetTcpBinding (
			Binding binding, SecurityMode security, bool reliableSession,
			TransferMode transferMode, TestLabel label)
		{
			label.EnterScope ("net-tcp");
			if (security == SecurityMode.Message) {
				Assert.That (binding, Is.InstanceOfType (typeof(CustomBinding)), label.Get ());
			} else {
				Assert.That (binding, Is.InstanceOfType (typeof(NetTcpBinding)), label.Get ());
				var netTcp = (NetTcpBinding)binding;
				Assert.That (netTcp.EnvelopeVersion, Is.EqualTo (EnvelopeVersion.Soap12), label.Get ());
				Assert.That (netTcp.MessageVersion, Is.EqualTo (MessageVersion.Soap12WSAddressing10), label.Get ());
				Assert.That (netTcp.Scheme, Is.EqualTo ("net.tcp"), label.Get ());
				Assert.That (netTcp.TransferMode, Is.EqualTo (transferMode), label.Get ());

				label.EnterScope ("security");
				Assert.That (netTcp.Security, Is.Not.Null, label.Get ());
				Assert.That (netTcp.Security.Mode, Is.EqualTo (security), label.Get ());

				Assert.That (netTcp.Security.Transport, Is.Not.Null, label.Get ());
				Assert.That (netTcp.Security.Transport.ProtectionLevel, Is.EqualTo (ProtectionLevel.EncryptAndSign), label.Get ());
				Assert.That (netTcp.Security.Transport.ClientCredentialType, Is.EqualTo (TcpClientCredentialType.Windows), label.Get ());
				label.LeaveScope ();
			}

			label.EnterScope ("elements");
			
			var elements = binding.CreateBindingElements ();
			Assert.That (elements, Is.Not.Null, label.Get ());

			TcpTransportBindingElement transportElement = null;
			TransactionFlowBindingElement transactionFlowElement = null;
			BinaryMessageEncodingBindingElement encodingElement = null;
			WindowsStreamSecurityBindingElement windowsStreamElement = null;
			ReliableSessionBindingElement reliableSessionElement = null;
			TransportSecurityBindingElement transportSecurityElement = null;
			SslStreamSecurityBindingElement sslStreamElement = null;
			SymmetricSecurityBindingElement symmSecurityElement = null;
			
			foreach (var element in elements) {
				if (element is TcpTransportBindingElement)
					transportElement = (TcpTransportBindingElement)element;
				else if (element is TransactionFlowBindingElement)
					transactionFlowElement = (TransactionFlowBindingElement)element;
				else if (element is BinaryMessageEncodingBindingElement)
					encodingElement = (BinaryMessageEncodingBindingElement)element;
				else if (element is WindowsStreamSecurityBindingElement)
					windowsStreamElement = (WindowsStreamSecurityBindingElement)element;
				else if (element is ReliableSessionBindingElement)
					reliableSessionElement = (ReliableSessionBindingElement)element;
				else if (element is TransportSecurityBindingElement)
					transportSecurityElement = (TransportSecurityBindingElement)element;
				else if (element is SslStreamSecurityBindingElement)
					sslStreamElement = (SslStreamSecurityBindingElement)element;
				else if (element is SymmetricSecurityBindingElement)
					symmSecurityElement = (SymmetricSecurityBindingElement)element;
				else
					Assert.Fail (string.Format (
						"Unknown element `{0}'.", element.GetType ()), label.Get ());
			}

			label.EnterScope ("windows-stream");
			if (security == SecurityMode.Transport) {
				Assert.That (windowsStreamElement, Is.Not.Null, label.Get ());
				Assert.That (windowsStreamElement.ProtectionLevel, Is.EqualTo (ProtectionLevel.EncryptAndSign), label.Get ());
			} else {
				Assert.That (windowsStreamElement, Is.Null, label.Get ());
			}
			label.LeaveScope ();

			label.EnterScope ("reliable-session");
			if (reliableSession) {
				Assert.That (reliableSessionElement, Is.Not.Null, label.Get ());
			} else {
				Assert.That (reliableSessionElement, Is.Null, label.Get ());
			}
			label.LeaveScope ();

			label.EnterScope ("encoding");
			Assert.That (encodingElement, Is.Not.Null, label.Get ());
			label.LeaveScope ();

			label.EnterScope ("transaction");
			if (security == SecurityMode.Message) {
				Assert.That (transactionFlowElement, Is.Null, label.Get ());
			} else {
				Assert.That (transactionFlowElement, Is.Not.Null, label.Get ());
			}
			label.LeaveScope ();

			label.EnterScope ("transport");
			Assert.That (transportElement, Is.Not.Null, label.Get ());

			Assert.That (transportElement.Scheme, Is.EqualTo ("net.tcp"), label.Get ());
			Assert.That (transportElement.TransferMode, Is.EqualTo (transferMode), label.Get ());
			label.LeaveScope (); // transport

			label.EnterScope ("security");
			switch (security) {
			case SecurityMode.None:
			case SecurityMode.Transport:
				Assert.That (transportSecurityElement, Is.Null, label.Get ());
				Assert.That (sslStreamElement, Is.Null, label.Get ());
				Assert.That (symmSecurityElement, Is.Null, label.Get ());
				break;
			case SecurityMode.TransportWithMessageCredential:
				Assert.That (transportSecurityElement, Is.Not.Null, label.Get ());
				Assert.That (sslStreamElement, Is.Not.Null, label.Get ());
				Assert.That (symmSecurityElement, Is.Null, label.Get ());
				break;
			case SecurityMode.Message:
				Assert.That (transportSecurityElement, Is.Null, label.Get ());
				Assert.That (sslStreamElement, Is.Null, label.Get ());
				Assert.That (symmSecurityElement, Is.Not.Null, label.Get ());
				break;
			default:
				throw new InvalidOperationException ();
			}
			label.LeaveScope ();

			label.LeaveScope (); // elements
			label.LeaveScope (); // net-tcp
		}
		public static void AssertConfig (MetadataSet metadata, XmlDocument xml, TestLabel label)
		{
			label.EnterScope ("import");
			var importer = new WsdlImporter (metadata);
			var endpoints = importer.ImportAllEndpoints ();
			CheckImportErrors (importer, label);
			Assert.That (endpoints.Count, Is.AtLeast (1), label.Get ());
			label.LeaveScope ();

			var nav = xml.CreateNavigator ();

			// FIXME: Check endpoints.

			label.EnterScope ("endpoints");
			var endpointIter = nav.Select ("/configuration/system.serviceModel/client/endpoint");
			Assert.That (endpointIter.Count, Is.EqualTo (endpoints.Count), label.Get ());
			
			label.LeaveScope ();
		}