public void ExportBar1Contract()
        {
            WsdlExporter        we = new WsdlExporter();
            ContractDescription cd = ContractDescription.GetContract(typeof(Bar1));

            we.ExportContract(cd);
        }
        public void ExportMessageContract()
        {
            WsdlExporter        we = new WsdlExporter();
            ContractDescription cd = ContractDescription.GetContract(typeof(IFoo2));

            we.ExportContract(cd);
        }
Пример #3
0
        public static XmlDocument GetSingleWsdl <TContract>(out string[] errors)
        {
            var description  = ContractDescription.GetContract(typeof(TContract));
            var wsdlExporter = new WsdlExporter();

            wsdlExporter.ExportContract(description);
            errors = wsdlExporter.Errors.Select(e => e.Message).ToArray();

            var wsdlMetadata = wsdlExporter.GetGeneratedMetadata();

            var asy            = Assembly.GetAssembly(typeof(WsdlExporter));
            var wsdlHelperType = asy.GetType("System.ServiceModel.Description.WsdlHelper", true);
            var getSingleWsdl  = wsdlHelperType.GetMethod("GetSingleWsdl", BindingFlags.Public | BindingFlags.Static);

            var parameters = new object[]
            {
                wsdlMetadata
            };
            var serviceDescription = (ServiceDescription)getSingleWsdl.Invoke(null, parameters);

            var doc    = new XmlDocument();
            var writer = doc.CreateNavigator().AppendChild();

            try
            {
                serviceDescription.Write(writer);

                return(doc);
            }
            finally
            {
                writer.Close();
            }
        }
        public void ExportContractInvalid1()
        {
            WsdlExporter we = new WsdlExporter();

            we.ExportContract(ContractDescription.GetContract(typeof(IEchoService2)));
            //Duplicate contract QNames not allowed
            ExportContractExpectException(we, ContractDescription.GetContract(typeof(IEchoService2)),
                                          typeof(ArgumentException), "ExportContractInvalid1");
        }
Пример #5
0
        public void DuplicateContract()
        {
            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.ExportContract(cd);
            exporter.ExportEndpoint(endpoint);

            CheckExport(
                exporter, new QName("MyContract", "http://tempuri.org/"),
                "BasicHttpBinding", 1, label);
        }
        public void ExportContract2()
        {
            WsdlExporter we = new WsdlExporter();

            we.ExportContract(ContractDescription.GetContract(typeof(IFoo1)));

            MetadataSet ms = we.GetGeneratedMetadata();

            Assert.AreEqual(5, ms.MetadataSections.Count);
        }
        public void ExportContractInvalid2()
        {
            WsdlExporter we = new WsdlExporter();

            we.ExportContract(ContractDescription.GetContract(typeof(IEchoService2)));
            //Invalid as IEchoService3.Echo is http://tempuri.org/Echo message which has already been exported
            //Even though, the service name is different
            ExportContractExpectException(we, ContractDescription.GetContract(typeof(IEchoService3)),
                                          typeof(InvalidOperationException), "ExportContractInvalid2");
        }
Пример #8
0
        static MetadataSet GetMetadata(Type serviceType)
        {
            var description = ContractDescription.GetContract(serviceType);
            var exporter    = new WsdlExporter();

            exporter.ExportContract(description);
            var metadata = exporter.GetGeneratedMetadata();

            return(metadata);
        }
        public void ExportContract2a()
        {
            WsdlExporter we = new WsdlExporter();

            we.ExportContract(ContractDescription.GetContract(typeof(IFoo1)));
            //IFoo1a.Op1 is the same operations as IFoo1.Op1, so cant be exported
            //the message element for both is the same
            //(Compared by names not signature)
            ExportContractExpectException(we, ContractDescription.GetContract(typeof(IFoo1a)),
                                          typeof(InvalidOperationException), "ExportContract2a");
        }
        public void ExportContract1()
        {
            WsdlExporter we = new WsdlExporter();

            we.ExportContract(ContractDescription.GetContract(typeof(IEchoService)));

            MetadataSet ms = we.GetGeneratedMetadata();

            Assert.AreEqual(5, ms.MetadataSections.Count);

            CheckContract_IEchoService(ms, "ExportContract1");
        }
Пример #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WcfMessageInspector" /> class.
        /// </summary>
        /// <param name="serviceEndpoint">The service endpoint.</param>
        public WcfMessageInspector(ServiceEndpoint serviceEndpoint)
        {
            this._serviceEndpoint = serviceEndpoint;

            if (this._serviceEndpoint != null)
            {
                this._oneWayActions = new HashSet <string>();

                try
                {
                    foreach (var operation in this._serviceEndpoint.Contract.Operations)
                    {
                        if (operation.IsOneWay)
                        {
                            this._oneWayActions.Add(operation.Messages[0].Action);
                        }
                    }
                }
                catch (Exception e)
                {
                    InternalLogger.Log(e);
                }

                try
                {
                    List <MessageDescription> wildcardActions = new List <MessageDescription>();

                    foreach (OperationDescription operation in this._serviceEndpoint.Contract.Operations)
                    {
                        foreach (MessageDescription message in operation.Messages)
                        {
                            if (message.RemoveActionWildcard())
                            {
                                wildcardActions.Add(message);
                            }
                        }
                    }

                    WsdlExporter wsdlExporter = new WsdlExporter();
                    wsdlExporter.ExportContract(this._serviceEndpoint.Contract);
                    this._xmlSchemaSet = wsdlExporter.GeneratedXmlSchemas;

                    foreach (MessageDescription message in wildcardActions)
                    {
                        message.SetActionWildcard();
                    }
                }
                catch (Exception e)
                {
                    InternalLogger.Log(e);
                }
            }
        }
Пример #12
0
        //somebody fix this name!
        void ExportContractExpectException(WsdlExporter we, ContractDescription cd, Type exception_type, string msg)
        {
            try {
                we.ExportContract(cd);
            } catch (Exception e) {
                if (e.GetType() == exception_type)
                {
                    return;
                }
                Assert.Fail(String.Format("[{0}] Expected {1}, but got : {2}", msg, exception_type, e));
            }

            Assert.Fail(String.Format("[{0}] Expected {1}", msg, exception_type));
        }
            class XsdValiationBehavior : IEndpointBehavior...     //omitted for clarity

                static void Main(string[] args)
        {
            ContractDescription cd = ContractDescription.GetContract(typeof(ServiceReference1.IService1));

            WsdlExporter exporter = new WsdlExporter();

            exporter.ExportContract(cd);

            XmlSchemaSet set = exporter.GeneratedXmlSchemas;

            // Client implementation omitted for clarity sake.
            var client = < some client here >;   //omitted for clarity

            var validation = new XsdValidationBehavior(new XmlSchemaSet {
                xmlSchema
            });

            client.ChannelFactory.Behaviours.Add(validation);
        }
        //FIXME: One check not working, BeginGetResult
        public void ExportMexContract()
        {
            WsdlExporter        we = new WsdlExporter();
            ContractDescription cd = ContractDescription.GetContract(typeof(IMetadataExchange));

            we.ExportContract(cd);

            MetadataSet ms = we.GetGeneratedMetadata();

            WSServiceDescription sd = GetServiceDescription(ms, "http://schemas.microsoft.com/2006/04/mex", "ExportMexContract");

            CheckMessage(sd, "IMetadataExchange_Get_InputMessage", "request", "http://schemas.microsoft.com/Message:MessageBody", true, "#exc0");
            CheckMessage(sd, "IMetadataExchange_Get_OutputMessage", "GetResult", "http://schemas.microsoft.com/Message:MessageBody", true, "#exc1");

            //PortType
            PortType port_type = sd.PortTypes ["IMetadataExchange"];

            Assert.IsNotNull(port_type, "#exc2, PortType named IMetadataExchange not found.");

            Assert.AreEqual(1, port_type.Operations.Count, "#exc3");
            Operation op = port_type.Operations [0];

            Assert.AreEqual("Get", op.Name, "#exc4");

            Assert.AreEqual(2, op.Messages.Count, "#exc5");
            CheckOperationMessage(op.Messages [0], "http://schemas.microsoft.com/2006/04/mex:IMetadataExchange_Get_InputMessage",
                                  typeof(OperationInput), "http://schemas.xmlsoap.org/ws/2004/09/transfer/Get");

            CheckOperationMessage(op.Messages [1], "http://schemas.microsoft.com/2006/04/mex:IMetadataExchange_Get_OutputMessage",
                                  typeof(OperationOutput), "http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse");

            CheckSpecialMessage(ms, "#exc6");

            Assert.AreEqual(1, we.GeneratedWsdlDocuments.Count, "GeneratedWsdlDocuments.Count");
            Assert.AreEqual(1, we.GeneratedXmlSchemas.Count, "GeneratedXmlSchemas.Count");
        }