예제 #1
0
        /// <summary>
        /// Build a contract for the specified TX
        /// </summary>
        /// <param name="className">The full class name to use, i.e.: Dcs.SomeNamespace.ITx1</param>
        /// <param name="tx">The TX to build a contract for</param>
        /// <returns>The interface type for the contract</returns>
        public Type BuildContract(string className, tTransaction tx)
        {
            // Get a type builder
            TypeBuilder typeBuilder = _moduleBuilder.DefineType(className, TypeAttributes.Public | TypeAttributes.AutoLayout | TypeAttributes.Interface | TypeAttributes.Abstract | TypeAttributes.AnsiClass);

            // Add the ServiceContract attribute
            PropertyInfo namespaceProperty = typeof(ServiceContractAttribute).GetProperty("Namespace", BindingFlags.Instance | BindingFlags.Public);

            typeBuilder.SetCustomAttribute(new CustomAttributeBuilder(typeof(ServiceContractAttribute).GetConstructor(Type.EmptyTypes), new object[0],
                                                                      new PropertyInfo[] { namespaceProperty }, new object[] { string.Format(this._soapNamespaceFormat, tx.TxId, tx.Version) }));
            typeBuilder.SetCustomAttribute(new CustomAttributeBuilder(typeof(TxDetailsAttribute).GetConstructor(new Type[] { typeof(string) }), new object[] { tx.TxId }));

            // Build the execute method
            AddExecuteMethod(tx, typeBuilder);

            return(typeBuilder.CreateType());
        }
예제 #2
0
        private static void AddExecuteMethod(tTransaction tx, TypeBuilder typeBuilder)
        {
            MethodBuilder methodBuilder = typeBuilder.DefineMethod("Execute", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Abstract,
                                                                   tx.ReturnType, (from p in tx.Parameters
                                                                                   select p.ParameterType).ToArray());
            // Add OperationContract attribute
            PropertyInfo isOneWayProperty = typeof(OperationContractAttribute).GetProperty("IsOneWay", BindingFlags.Instance | BindingFlags.Public);

            methodBuilder.SetCustomAttribute(new CustomAttributeBuilder(typeof(OperationContractAttribute).GetConstructor(Type.EmptyTypes), new object[0],
                                                                        new PropertyInfo[] { isOneWayProperty }, new object[] { tx.IsOneWay }));
            int pos = 1;

            foreach (var parameter in tx.Parameters)
            {
                ParameterBuilder parameterBuilder = methodBuilder.DefineParameter(pos, ParameterAttributes.In, parameter.Name);
                pos++;
            }
        }
 public TxServiceHost(string serviceName, string contractsNamespace, tTransaction[] txList, params Uri[] baseAddresses)
     : base(GenerateService(serviceName, contractsNamespace, txList), baseAddresses)
 {
     foreach (Type serviceContract in this.Description.ServiceType.GetInterfaces())
     {
         TxDetailsAttribute attr = (TxDetailsAttribute)serviceContract.GetCustomAttributes(typeof(TxDetailsAttribute), true).FirstOrDefault();
         if (attr != null)
         {
             // Contract is hosted
             tTransaction tx = (from t in txList
                                where t.TxId == attr.TxId
                                select t).FirstOrDefault();
             if (tx != null)
             {
                 foreach (var binding in tx.Bindings)
                 {
                     this.AddServiceEndpoint(serviceContract, binding, string.Format("{0}/{1}", tx.TxId, tx.Version));
                 }
             }
         }
     }
 }
 private static string GetTxServiceContractName(string contractsNamespace, tTransaction tx)
 {
     return(string.Format("{0}.I{1}", contractsNamespace, tx.TxId));
 }
예제 #5
0
        static void Main(string[] args)
        {
            tTransaction[] txList = new tTransaction[]
            {
                //new tTransaction("Tx1",1,typeof(string),false,
                //    new TxParameter[]
                //    {
                //        new TxParameter("name",typeof(string)),
                //        new TxParameter("dateOfBirth",typeof(DateTime)),
                //    },
                //    new Binding[]
                //    {
                //        new NetTcpBinding(),
                //        new BasicHttpBinding(),
                //    }),
                //new tTransaction("Tx2",1,typeof(int),false,
                //    new TxParameter[]
                //    {
                //        new TxParameter("num",typeof(int))
                //    },
                //    new Binding[]
                //    {
                //        new NetTcpBinding(),
                //        new NetNamedPipeBinding(),
                //    }),
                //new tTransaction("Tx3",2,typeof(DateTime),false,
                //    new TxParameter[]
                //    {
                //        new TxParameter("firstParameter",typeof(int))
                //    },
                //    new Binding[]
                //    {
                //        new NetTcpBinding(),
                //    }),
                new tTransaction("Tx4", 1, null, true,
                                 new TxParameter[]
                {
                    new TxParameter("someVAlue", typeof(string))
                },
                                 new Binding[]
                {
                    new BasicHttpBinding(),
                }),
                //new tTransaction("Tx5",1,null,false,
                //    new TxParameter[]
                //    {
                //    },
                //    new Binding[]
                //    {
                //        new BasicHttpBinding(),
                //    }),
                //    new tTransaction("Tx6",1,null,false,
                //    new TxParameter[]
                //    {
                //        new TxParameter("Person",typeof(Person))
                //    },
                //    new Binding[]
                //    {
                //        new BasicHttpBinding(),
                //    }),
            };

            using (TxServiceHost host = new TxServiceHost("Dcs.TxHosting.TxHost", "Dcs.TxHosting", txList))
            {
                host.Open();
                Console.WriteLine("Ready");
                Console.ReadLine();
            }
        }