Ejemplo n.º 1
1
		public void ExportEndpointTest ()
		{
			WsdlExporter we = new WsdlExporter ();

			ServiceEndpoint se = new ServiceEndpoint (ContractDescription.GetContract (typeof (IEchoService)));
			se.Binding = new BasicHttpBinding ();
			se.Address = new EndpointAddress ("http://localhost:8080");
			//TEST Invalid name: 5se.Name = "Service#1";
			//se.Name = "Service0";
			//se.ListenUri = new Uri ("http://localhost:8080/svc");

			we.ExportEndpoint (se);

			MetadataSet ms = we.GetGeneratedMetadata ();
			Assert.AreEqual (6, ms.MetadataSections.Count);
			CheckContract_IEchoService (ms, "#eet01");

			WSServiceDescription sd = GetServiceDescription (ms, "http://tempuri.org/", "ExportEndpointTest");
			CheckServicePort (GetService (sd, "service", "ExportEndpointTest"),
				"BasicHttpBinding_IEchoService", new XmlQualifiedName ("BasicHttpBinding_IEchoService", "http://tempuri.org/"),
				"http://localhost:8080/", "#eet02");

			CheckBasicHttpBinding (sd, "BasicHttpBinding_IEchoService", new XmlQualifiedName ("IEchoService", "http://myns/echo"),
				"Echo", "http://myns/echo/IEchoService/Echo", true, true, "#eet03");
		}
        private XmlDocument ExportEndpoints()
        {
            WsdlExporter exporter = new WsdlExporter();
            foreach (ServiceEndpoint ep in endpoints)
            {
                exporter.ExportEndpoint(ep);
            }

            MetadataSet metadataSet = exporter.GetGeneratedMetadata();
            StringBuilder b = new StringBuilder();
            StringWriter sw = new StringWriter(b);
            XmlTextWriter tw = new XmlTextWriter(sw);
            foreach (MetadataSection section in metadataSet.MetadataSections)
            {
                if (section.Metadata is System.Web.Services.Description.ServiceDescription)
                {
                    System.Web.Services.Description.ServiceDescription sd = (System.Web.Services.Description.ServiceDescription)section.Metadata;
                    sd.Write(tw);
                }
            }

            string wcfWsdl = b.ToString();
            // Read it in to an XmlDocument.
            XmlDocument wcfWsdlDoc = new XmlDocument();
            wcfWsdlDoc.LoadXml(wcfWsdl);
            return wcfWsdlDoc;
        }
Ejemplo n.º 3
0
 void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     WsdlExporter wsdlExporter = new WsdlExporter();
     wsdlExporter.ExportEndpoint(endpoint);
     endpointDispatcher.DispatchRuntime.MessageInspectors.Add(
         new XsdValidationInspector(wsdlExporter.GeneratedXmlSchemas));
 }
Ejemplo n.º 4
0
		public static MetadataSet BasicHttp ()
		{
			var exporter = new WsdlExporter ();
			
			var cd = new ContractDescription ("MyContract");
			
			exporter.ExportEndpoint (new ServiceEndpoint (
				cd, new BasicHttpBinding (), new EndpointAddress (HttpUri)));
			
			return exporter.GetGeneratedMetadata ();
		}
Ejemplo n.º 5
0
		public static MetadataSet BasicHttp_TransportSecurity ()
		{
			var exporter = new WsdlExporter ();
			
			var cd = new ContractDescription ("MyContract");
			
			var binding = new BasicHttpBinding ();
			binding.Security.Mode = BasicHttpSecurityMode.Transport;
			
			exporter.ExportEndpoint (new ServiceEndpoint (
				cd, binding, new EndpointAddress (HttpUri)));
			
			return exporter.GetGeneratedMetadata ();
		}
Ejemplo n.º 6
0
		public static MetadataSet BasicHttp_MessageSecurity ()
		{
			var exporter = new WsdlExporter ();
			
			var cd = new ContractDescription ("MyContract");
			
			var binding = new BasicHttpBinding ();
			binding.Security.Mode = BasicHttpSecurityMode.Message;
			binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;
			
			exporter.ExportEndpoint (new ServiceEndpoint (
				cd, binding, new EndpointAddress (HttpUri)));
			
			return exporter.GetGeneratedMetadata ();
		}
Ejemplo n.º 7
0
		public void SimpleExport ()
		{
			var label = new TestLabel ("DuplicateContract");
			
			var cd = new ContractDescription ("MyContract");
			var endpoint = new ServiceEndpoint (
				cd, new BasicHttpBinding (), new EndpointAddress (HttpUri));
			
			var exporter = new WsdlExporter ();
			exporter.ExportContract (cd);
			exporter.ExportEndpoint (endpoint);
			
			CheckExport (
				exporter, new QName ("MyContract", "http://tempuri.org/"),
				"BasicHttpBinding", 1, label);
		}
Ejemplo n.º 8
0
		public void ExportEndpointTest5 () {
			WsdlExporter we = new WsdlExporter ();

			ServiceEndpoint se = new ServiceEndpoint (ContractDescription.GetContract (typeof (IEchoService)));
			se.Binding = new BasicHttpBinding ();
			se.Address = new EndpointAddress ("http://localhost:8080");

			we.ExportEndpoint (se);

			MetadataSet ms = we.GetGeneratedMetadata ();
			Assert.AreEqual (6, ms.MetadataSections.Count);
			WSServiceDescription wsd = GetServiceDescription (ms, "http://tempuri.org/", "ExportEndpointTest5#1");

			SoapBinding soapBinding = (SoapBinding) wsd.Bindings [0].Extensions [0];
			Assert.AreEqual (SoapBindingStyle.Document, soapBinding.Style, "soapBinding.Style");
			Assert.AreEqual (SoapBinding.HttpTransport, soapBinding.Transport, "soapBinding.Transport");
		}
Ejemplo n.º 9
0
		public static MetadataSet NetTcp_TransferMode ()
		{
			var exporter = new WsdlExporter ();
			
			var cd = new ContractDescription ("MyContract");
			
			var binding = new NetTcpBinding (SecurityMode.None, false);
			binding.TransferMode = TransferMode.Streamed;

			exporter.ExportEndpoint (new ServiceEndpoint (
				cd, binding, new EndpointAddress (NetTcpUri)));
			
			var doc = exporter.GetGeneratedMetadata ();
			return doc;
		}
Ejemplo n.º 10
0
		public static MetadataSet NetTcp_ReliableSession ()
		{
			var exporter = new WsdlExporter ();
			
			var cd = new ContractDescription ("MyContract");
			
			var binding = new NetTcpBinding (SecurityMode.None, true);
			
			exporter.ExportEndpoint (new ServiceEndpoint (
				cd, binding, new EndpointAddress (NetTcpUri)));
			
			var doc = exporter.GetGeneratedMetadata ();
			return doc;
		}
Ejemplo n.º 11
0
		public static MetadataSet NetTcp_TransportWithMessageCredential ()
		{
			var exporter = new WsdlExporter ();
			
			var cd = new ContractDescription ("MyContract");
			
			exporter.ExportEndpoint (new ServiceEndpoint (
				cd, new NetTcpBinding (SecurityMode.TransportWithMessageCredential, false),
				new EndpointAddress (NetTcpUri)));
			
			var doc = exporter.GetGeneratedMetadata ();
			return doc;
		}
Ejemplo n.º 12
0
		public static MetadataSet BasicHttps_TransportWithMessageCredential ()
		{
			var exporter = new WsdlExporter ();
			
			var cd = new ContractDescription ("MyContract");
			
			var binding = new BasicHttpsBinding (BasicHttpsSecurityMode.TransportWithMessageCredential);
			
			exporter.ExportEndpoint (new ServiceEndpoint (
				cd, binding, new EndpointAddress (HttpsUri)));
			
			var doc = exporter.GetGeneratedMetadata ();
			return doc;
		}
Ejemplo n.º 13
0
		public static MetadataSet BasicHttp_Config ()
		{
			var exporter = new WsdlExporter ();
			
			var cd = ContractDescription.GetContract (typeof (IMyContract));
			
			var binding = new BasicHttpBinding ();
			
			exporter.ExportEndpoint (new ServiceEndpoint (
				cd, binding, new EndpointAddress (HttpUri)));
			
			return exporter.GetGeneratedMetadata ();
		}
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            using (ServiceHost host = new ServiceHost(typeof(WcfServiceLibrary1.Service1)))
            {
                // surrogate definition..
                foreach (ServiceEndpoint ep in host.Description.Endpoints)
                {
                    foreach (OperationDescription op in ep.Contract.Operations)
                    {
                        DataContractSerializerOperationBehavior dataContractBehavior =
                            op.Behaviors.Find<DataContractSerializerOperationBehavior>()
                            as DataContractSerializerOperationBehavior;
                        if (dataContractBehavior != null)
                        {
                            dataContractBehavior.DataContractSurrogate = new valToTransferAsBytes();
                        }
                        else
                        {
                            dataContractBehavior = new DataContractSerializerOperationBehavior(op);
                            dataContractBehavior.DataContractSurrogate = new valToTransferAsBytes();
                            op.Behaviors.Add(dataContractBehavior);
                        }
                    }
                }

                // set up exporter with surrogate definition..
                WsdlExporter exporter = new WsdlExporter();
                object dataContractExporter;
                XsdDataContractExporter xsdInventoryExporter;
                if (!exporter.State.TryGetValue(typeof(XsdDataContractExporter),
                    out dataContractExporter))
                {
                    xsdInventoryExporter = new XsdDataContractExporter(exporter.GeneratedXmlSchemas);
                }
                else
                    xsdInventoryExporter = (XsdDataContractExporter)dataContractExporter;
                exporter.State.Add(typeof(XsdDataContractExporter), xsdInventoryExporter);


                if (xsdInventoryExporter.Options == null)
                    xsdInventoryExporter.Options = new ExportOptions();
                xsdInventoryExporter.Options.DataContractSurrogate = new valToTransferAsBytes();

                // export the endpoints..

                

                ServiceEndpointCollection sec = host.Description.Endpoints;
                foreach (ServiceEndpoint se in sec)
                {
                    Console.WriteLine(se.Name);
                    exporter.ExportEndpoint(se);
                }

                MetadataSet docs = null;
                docs = exporter.GetGeneratedMetadata();

                host.Description.


                host.Open();

                PrintDescription(host);

                Console.WriteLine("The Trading Service is available.  Press any key to exit.");
                Console.ReadKey();

                host.Close();
            }

        }
Ejemplo n.º 15
0
		public static MetadataSet BasicHttp_Mtom ()
		{
			var exporter = new WsdlExporter ();
			
			var cd = new ContractDescription ("MyContract");
			
			var binding = new BasicHttpBinding ();
			binding.MessageEncoding = WSMessageEncoding.Mtom;
			
			exporter.ExportEndpoint (new ServiceEndpoint (
				cd, binding, new EndpointAddress (HttpUri)));
			
			var doc = exporter.GetGeneratedMetadata ();
			return doc;
		}
		private static void ExportMetadata(ServiceEndpoint endpoint, EndpointDiscoveryBehavior discovery)
		{
			var exporter = new WsdlExporter();
			exporter.ExportEndpoint(endpoint);
			var metadata = exporter.GetGeneratedMetadata();

			var document = new XDocument();
			using (var xmlWriter = document.CreateWriter())
			{
				xmlWriter.WriteStartElement(WcfConstants.EndpointMetadata.LocalName, 
											WcfConstants.EndpointMetadata.Namespace.NamespaceName);
				metadata.WriteTo(xmlWriter);
				xmlWriter.WriteEndElement();
				xmlWriter.Flush();
			}

			discovery.Extensions.Add(document.Element(WcfConstants.EndpointMetadata));
		}
Ejemplo n.º 17
0
		public static MetadataSet BasicHttp_Config2 ()
		{
			var exporter = new WsdlExporter ();
			
			var cd = ContractDescription.GetContract (typeof (IMyContract));
			
			exporter.ExportEndpoint (new ServiceEndpoint (
				cd, new BasicHttpBinding (),
				new EndpointAddress (HttpUri)));
			exporter.ExportEndpoint (new ServiceEndpoint (
				cd, new NetTcpBinding (SecurityMode.None, false),
				new EndpointAddress (NetTcpUri)));
			
			return exporter.GetGeneratedMetadata ();
		}
Ejemplo n.º 18
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 ();
		}
Ejemplo n.º 19
0
		public void ExportEndpointTest2 ()
		{
			WsdlExporter we = new WsdlExporter ();

			ServiceEndpoint se = new ServiceEndpoint (ContractDescription.GetContract (typeof (IEchoService2)));
			se.Binding = new BasicHttpBinding ();
			se.Address = new EndpointAddress ("http://localhost:8080");
			we.ExportEndpoint (se);

			MetadataSet ms = we.GetGeneratedMetadata ();
			Assert.AreEqual (5, ms.MetadataSections.Count);

			WSServiceDescription sd = ms.MetadataSections [0].Metadata as WSServiceDescription;
			CheckContract_IEchoService2 (ms, "#eet20");
			CheckServicePort (GetService (GetServiceDescription (ms, "http://tempuri.org/", "#eet21"), "service", "ExportEndpointTest"),
				"BasicHttpBinding_ThisIsEchoService", new XmlQualifiedName ("BasicHttpBinding_ThisIsEchoService", "http://tempuri.org/"),
				"http://localhost:8080/", "#eet22");

			CheckBasicHttpBinding (sd, "BasicHttpBinding_ThisIsEchoService",
				new XmlQualifiedName ("ThisIsEchoService", "http://tempuri.org/"),
				"Echo", "http://tempuri.org/ThisIsEchoService/Echo", true, true, "#eet03");

			//FIXME: CheckXmlSchema
		}
Ejemplo n.º 20
0
		public static MetadataSet BasicHttps_Certificate ()
		{
			var exporter = new WsdlExporter ();
			
			var cd = new ContractDescription ("MyContract");
			
			var binding = new BasicHttpsBinding ();
			binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
			
			exporter.ExportEndpoint (new ServiceEndpoint (
				cd, binding, new EndpointAddress (HttpsUri)));
			
			var doc = exporter.GetGeneratedMetadata ();
			return doc;
		}
Ejemplo n.º 21
0
		public static MetadataSet BasicHttp_NtlmAuth ()
		{
			var exporter = new WsdlExporter ();
			
			var cd = new ContractDescription ("MyContract");
			
			var binding = new BasicHttpBinding (BasicHttpSecurityMode.TransportCredentialOnly);
			binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
			
			exporter.ExportEndpoint (new ServiceEndpoint (
				cd, binding, new EndpointAddress (HttpUri)));
			
			var doc = exporter.GetGeneratedMetadata ();
			return doc;
		}
Ejemplo n.º 22
0
		public static MetadataSet NetTcp_MessageSecurity ()
		{
			var exporter = new WsdlExporter ();
			
			var cd = new ContractDescription ("MyContract");
			
			exporter.ExportEndpoint (new ServiceEndpoint (
				cd, new NetTcpBinding (SecurityMode.Message, false),
				new EndpointAddress (NetTcpUri)));
			
			return exporter.GetGeneratedMetadata ();
		}