public TChannel CreateChannel()
        {
            MessageEncoderFactory          encoderFactory = ComponentBuilder.GetMessageEncoderFactory(MessageVersion.Default, Encoding.UTF8);
            ServiceChannelProxy <TChannel> proxy          = new ServiceChannelProxy <TChannel>(this.Address, MessageVersion.Default, encoderFactory);
            ContractDescription            contract       = ContractDescription.GetContract(typeof(TChannel));

            foreach (OperationDescription operation in contract.Operations)
            {
                IClientMessageFormatter messageFormatter = (IClientMessageFormatter)ComponentBuilder.GetFormatter(operation, true);
                proxy.MessageFormatters.Add(operation.Name, messageFormatter);
            }
            return((TChannel)proxy.GetTransparentProxy());
        }
Esempio n. 2
0
        protected IHttpHandler CreateHttpHandler(Type serviceType)
        {
            MessageEncoderFactory encoderFactory = ComponentBuilder.GetMessageEncoderFactory(MessageVersion.Default, Encoding.UTF8);
            WcfHandler            handler        = new WcfHandler(serviceType, encoderFactory);
            Type interfaceType           = serviceType.GetInterfaces()[0];
            ContractDescription contract = ContractDescription.GetContract(interfaceType);

            foreach (OperationDescription operation in contract.Operations)
            {
                IDispatchMessageFormatter messageFormatter = (IDispatchMessageFormatter)ComponentBuilder.GetFormatter(operation, false);
                handler.MessageFormatters.Add(operation.Messages[0].Action, messageFormatter);

                IOperationInvoker operationInvoker = ComponentBuilder.GetOperationInvoker(operation.SyncMethod);
                handler.OperationInvokers.Add(operation.Messages[0].Action, operationInvoker);

                handler.Methods.Add(operation.Messages[0].Action, operation.SyncMethod);
            }
            return(handler);
        }