Beispiel #1
0
        /// <summary>
        /// 获取对象
        /// </summary>
        /// <param name="typeName"></param>
        /// <returns></returns>
        protected DynamicObject GetDynamicObject(string typeName)
        {
            DynamicObject obj = new DynamicObject(DynPro.ObjectType.Assembly.GetType(typeName, true, true));

            obj.CallConstructor();
            return(obj);
        }
Beispiel #2
0
        public static void Test()
        {
            string      baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host        = new ServiceHost(typeof(Service), new Uri(baseAddress));

            host.AddServiceEndpoint(typeof(IService), new BasicHttpBinding(), "");
            host.Description.Behaviors.Add(new ServiceMetadataBehavior {
                HttpGetEnabled = true
            });

            host.Open();
            Console.WriteLine("Host opened");

            DynamicProxyFactory factory = new DynamicProxyFactory(baseAddress + "?wsdl");

            DynamicProxy dynamicProxy = factory.CreateProxy("IService");

            Console.WriteLine(dynamicProxy.CallMethod("GetData", 123));

            Type          proxyType            = dynamicProxy.ProxyType;
            MethodInfo    getDataUsingDCMethod = proxyType.GetMethod("GetDataUsingDataContract");
            Type          dcType = getDataUsingDCMethod.GetParameters()[0].ParameterType;
            DynamicObject obj    = new DynamicObject(dcType);

            obj.CallConstructor();
            obj.SetProperty("BoolValue", true);
            obj.SetProperty("StringValue", "Hello world");

            DynamicObject result = new DynamicObject(
                dynamicProxy.CallMethod(
                    "GetDataUsingDataContract",
                    obj.ObjectInstance));

            Console.WriteLine(result.GetProperty("StringValue"));

            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
Beispiel #3
0
        public static void Test()
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
            host.AddServiceEndpoint(typeof(IService), new BasicHttpBinding(), "");
            host.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true });

            host.Open();
            Console.WriteLine("Host opened");

            DynamicProxyFactory factory = new DynamicProxyFactory(baseAddress + "?wsdl");

            DynamicProxy dynamicProxy = factory.CreateProxy("IService");
            Console.WriteLine(dynamicProxy.CallMethod("GetData", 123));

            Type proxyType = dynamicProxy.ProxyType;
            MethodInfo getDataUsingDCMethod = proxyType.GetMethod("GetDataUsingDataContract");
            Type dcType = getDataUsingDCMethod.GetParameters()[0].ParameterType;
            DynamicObject obj = new DynamicObject(dcType);
            obj.CallConstructor();
            obj.SetProperty("BoolValue", true);
            obj.SetProperty("StringValue", "Hello world");

            DynamicObject result = new DynamicObject(
                dynamicProxy.CallMethod(
                    "GetDataUsingDataContract",
                    obj.ObjectInstance));

            Console.WriteLine(result.GetProperty("StringValue"));

            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }