Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Giving a second for the host to open...");
            Thread.Sleep(1000);

            string endpointAddress = "http://" + Environment.MachineName + ":8000/Service";
            var factory = new ChannelFactory<Server.IDynamicContract>(new BasicHttpBinding(), new EndpointAddress(endpointAddress));
            foreach (var operation in factory.Endpoint.Contract.Operations)
            {
                operation.Behaviors.Find<DataContractSerializerOperationBehavior>().DataContractResolver = new DynamicTypeResolver();
            }

            var proxy = factory.CreateChannel();
            Console.WriteLine("Created the proxy");

            object product = CreateProduct();
            Console.WriteLine("Product: {0}", product);

            Console.WriteLine("Calling the service passing the product...");
            MyHolder input = new MyHolder { MyObject = product };
            MyHolder output = proxy.EchoHolder(input);
            Console.WriteLine("Result: {0}", output);
            Console.WriteLine();

            Console.WriteLine("Now passing a product not known by the server");
            object address = CreateAddress();
            string addressString = proxy.PutHolder(new MyHolder { MyObject = address });
            Console.WriteLine("Result: {0}", addressString);
            Console.WriteLine();

            Type[] dynamicTypes = address.GetType().Assembly.GetTypes();
            Console.WriteLine("Do we know about Person yet?");
            Console.WriteLine("All dynamic types so far");
            foreach (var dynamicType in dynamicTypes)
            {
                Console.WriteLine("  {0}", dynamicType.Name);
            }

            Console.WriteLine("Retrieving a new type from the server");
            output = proxy.GetHolder("Person", new string[] { "Name", "Age" }, new object[] { "John Doe", 33 });
            Console.WriteLine("Output: {0}", output);
            Console.WriteLine("Type of output value: {0}", output.MyObject.GetType());
            Console.WriteLine("Is it on the same assembly as the other types? {0}",
                output.MyObject.GetType().Assembly.Equals(address.GetType().Assembly));
        }
Beispiel #2
0
 public MyHolder EchoHolder(MyHolder holder)
 {
     Console.WriteLine("In service, holder = {0}", holder);
     return holder;
 }
Beispiel #3
0
 public string PutHolder(MyHolder holder)
 {
     Console.WriteLine("In service, holder = {0}", holder);
     return holder.ToString();
 }