Exemplo n.º 1
0
        public void ExchangeMetadata()
        {
            // Service
            ServiceHost host = new ServiceHost(typeof(MetadataExchange));
            int         port = NetworkHelpers.FindFreePort();

            try {
                Binding binding = new BasicHttpBinding();
                binding.ReceiveTimeout = TimeSpan.FromSeconds(5);
                host.AddServiceEndpoint("IMetadataExchange",
                                        binding, new Uri("http://localhost:" + port));
                host.Open();
                // Client

                MetadataExchangeProxy proxy = new MetadataExchangeProxy(
                    new BasicHttpBinding(),
                    new EndpointAddress("http://localhost:" + port + "/"));
                proxy.Open();

                try {
                    Message req = Message.CreateMessage(MessageVersion.Soap11, "http://schemas.xmlsoap.org/ws/2004/09/transfer/Get");
                    Message res = proxy.Get(req);
                } finally {
                    proxy.Close();
                }
            } finally {
                // Service
                if (host.State == CommunicationState.Opened)
                {
                    host.Close();
                }
            }
        }