Ejemplo n.º 1
0
        static void ImportAllEndpoints()
        {
            EndpointAddress        mexAddress = new EndpointAddress(uri + "/mex");
            MetadataExchangeClient mexClient  = new MetadataExchangeClient(mexAddress);

            // Retrieve the metadata for all endpoints using metadata exchange protocol (mex).
            MetadataSet metadataSet = mexClient.GetMetadata();

            //Convert the metadata into endpoints
            WsdlImporter importer = new WsdlImporter(metadataSet);

            #region endpoints
            ServiceEndpointCollection endpoints = importer.ImportAllEndpoints();

            ContractDescription contract = ContractDescription.GetContract(typeof(ICalculator));
            // Communicate with each endpoint that supports the ICalculator contract.
            foreach (ServiceEndpoint ep in endpoints)
            {
                if (ep.Contract.Namespace.Equals(contract.Namespace) && ep.Contract.Name.Equals(contract.Name))
                {
                    // Create a client using the endpoint address and binding.
                    var client = new ChannelFactory <CalculatorClientChannel>(ep.Binding, new EndpointAddress(ep.Address.Uri)).CreateChannel();

                    // call operations
                    Console.WriteLine(client.Add(2, 3));

                    //Closing the client gracefully closes the connection and cleans up resources
                    client.Close();
                }
            }
            #endregion
        }
Ejemplo n.º 2
0
	public static void Main ()
	{
		var binding = new CustomBinding (
			new BinaryMessageEncodingBindingElement (),
			new HttpTransportBindingElement ());
		var address = new EndpointAddress ("http://localhost:8080");
		var proxy = new ChannelFactory<IFoo> (binding, address)
			.CreateChannel ();
		Console.WriteLine (proxy.Echo ("TEST FOR ECHO"));
		Console.WriteLine (proxy.Add (1000, 2000));
	}
Ejemplo n.º 3
0
    public static void Main()
    {
        var binding = new CustomBinding(
            new BinaryMessageEncodingBindingElement(),
            new HttpTransportBindingElement());
        var address = new EndpointAddress("http://localhost:8080");
        var proxy   = new ChannelFactory <IFoo> (binding, address)
                      .CreateChannel();

        Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
        Console.WriteLine(proxy.Add(1000, 2000));
    }
Ejemplo n.º 4
0
	public static void Main ()
	{
		var binding = new NetNamedPipeBinding ();
		binding.TransferMode = TransferMode.Streamed;
		binding.Security.Mode = NetNamedPipeSecurityMode.None;
		IFooChannel proxy = new ChannelFactory<IFooChannel> (
			binding,
			new EndpointAddress ("net.pipe://localhost/samplepipe")
			).CreateChannel ();
		proxy.Open ();
		Console.WriteLine (proxy.Echo ("TEST FOR ECHO"));
		Console.WriteLine (proxy.Add (1000, 2000));
	}
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            #region Exercise 1

            //IMath mathChannel =
            //new ChannelFactory<IMath>(new BasicHttpBinding(),
            //new EndpointAddress("http://localhost:8080/math")).CreateChannel();

            //MathTypes.MathRequest req = new MathTypes.MathRequest(25, 45);
            //MathTypes.MathResponse response = null;

            //MathTypes.IMath channel = new ChannelFactory<MathTypes.IMath>(
            //        new BasicHttpBinding(),
            //        new EndpointAddress("http://localhost:8080/math")).CreateChannel();
            //response = channel.Add(req);

            //Console.WriteLine();
            //Console.Write("Call via BasicProfileBinding: ");
            //Console.ForegroundColor = ConsoleColor.Green;
            //Console.Write(response.result);
            //Console.ResetColor();

            //Console.ReadKey(true);

            #endregion

            #region Exercise 2

            MathTypes.MathRequest        req  = new MathTypes.MathRequest(23, 44);
            MathTypes.MathRequestMessage mreq = new MathTypes.MathRequestMessage();
            mreq.request      = req;
            mreq.CustomHeader = 8;
            MathTypes.MathResponseMessage response = null;
            MathTypes.IMath channel = new ChannelFactory <MathTypes.IMath>(
                new BasicHttpBinding(),
                new EndpointAddress("http://localhost:8080/math")).CreateChannel();
            response = channel.Add(mreq);
            Console.WriteLine("Call via BasicProfileBinding: {0}",
                              response.response.result);
            Console.ReadKey(true);

            #endregion
            //Console.Write("Call via BasicHttpBinding: ");
            //Console.ForegroundColor = ConsoleColor.Green;
            //Console.Write(req);
            //Console.ResetColor();
            //Console.WriteLine();
            //Console.WriteLine();
            //Console.WriteLine("Press [Enter] to exit.");
            //Console.ReadLine();
        }
Ejemplo n.º 6
0
    public static void Main()
    {
        var binding = new NetTcpBinding();

        binding.Security.Mode = SecurityMode.None;
        IFooChannel proxy = new ChannelFactory <IFooChannel> (binding).CreateChannel(
            new EndpointAddress("urn:foo"),
            new Uri("net.tcp://localhost:8088"));

        proxy.Open();
        Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
        Console.WriteLine(proxy.SessionId);
        Console.WriteLine(proxy.Add(1000, 2000));
        Console.WriteLine(proxy.SessionId);
    }
Ejemplo n.º 7
0
    public static void Main()
    {
        var binding = new NetNamedPipeBinding();

        binding.TransferMode  = TransferMode.Streamed;
        binding.Security.Mode = NetNamedPipeSecurityMode.None;
        IFooChannel proxy = new ChannelFactory <IFooChannel> (
            binding,
            new EndpointAddress("net.pipe://localhost/samplepipe")
            ).CreateChannel();

        proxy.Open();
        Console.WriteLine(proxy.Echo("TEST FOR ECHO"));
        Console.WriteLine(proxy.Add(1000, 2000));
    }
Ejemplo n.º 8
0
        public void SimpleDuplexBuffered() // sample[svc|cli]4.exe
        {
            ServiceHost host     = new ServiceHost(typeof(Foo));
            var         bindingS = new CustomBinding(new BindingElement []
            {
                new BinaryMessageEncodingBindingElement(),
                new TcpTransportBindingElement()
            });

            bindingS.ReceiveTimeout = TimeSpan.FromSeconds(5);
            bindingS.OpenTimeout    = TimeSpan.FromSeconds(20);
            host.AddServiceEndpoint(typeof(IFoo),
                                    bindingS, new Uri("net.tcp://localhost:37564"));
            host.Description.Behaviors.Find <ServiceBehaviorAttribute> ().IncludeExceptionDetailInFaults = true;
            host.Open();

            try
            {
                for (int i = 0; i < 2; i++)
                {
                    var bindingC = new NetTcpBinding();
                    bindingC.Security.Mode = SecurityMode.None;
                    IFooChannel proxy = new ChannelFactory <IFooChannel> (bindingC, new EndpointAddress("net.tcp://localhost:37564/")).CreateChannel();
                    proxy.Open();
                    try
                    {
                        Assert.AreEqual("TEST FOR ECHO", proxy.Echo("TEST FOR ECHO"), "#1");
                        var sid = proxy.SessionId;
                        Assert.AreEqual(3000, proxy.Add(1000, 2000), "#2");
                        Assert.AreEqual(sid, proxy.SessionId, "#3");
                    }
                    finally
                    {
                        proxy.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
            }
            finally
            {
                host.Close();
            }
        }
Ejemplo n.º 9
0
        private static void Main(string[] args)
        {
            MathTypes.MathRequest req = new MathTypes.MathRequest();
            req.x = 23;
            req.y = 44;
            MathTypes.MathRequestMessage mreq = new MathTypes.MathRequestMessage();
            mreq.request      = req;
            mreq.CustomHeader = 8;
            MathTypes.MathResponseMessage response;
            //NetTcpBinding binding = new NetTcpBinding();
            //binding.Security.Mode = SecurityMode.Message;
            //binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
            //binding.Security.Transport.ProtectionLevel =
            //System.Net.Security.ProtectionLevel.EncryptAndSign;
            CustomBinding binding = new CustomBinding();

            binding.Elements.Add(new TextMessageEncodingBindingElement());
            binding.Elements.Add(new TcpTransportBindingElement());
            MathTypes.IMath channel = new ChannelFactory <MathTypes.IMath>("CustomBinding_IMath").CreateChannel();
            response = channel.Add(mreq);
            Console.WriteLine("Call via BasicProfileBinding: {0}",
                              response.response.result);
            Console.ReadKey(true);
        }