示例#1
0
        public static string ExecuteServiceLocal <S>(string destino, string securitytokenid, Func <S, string> methodName)
        {
            ChannelFactory <S> client = WCFHelper.CreateChannelFactoryJsonMapper <S>(destino);

            client.Open();
            S service = client.CreateChannel();

            using (new OperationContextScope((IContextChannel)service))
            {
                try
                {
                    WebOperationContext.Current.OutgoingRequest.Headers.Add("securitytokenid", securitytokenid);
                    string stream = methodName(service);
                    return(stream);
                }
                finally
                {
                    try
                    {
                        ((IClientChannel)service).Close();
                    }
                    catch (CommunicationException)
                    {
                        // Ignore various exceptions regarding the Channel's current state
                    }
                    catch (TimeoutException)
                    {
                        // Ignore Timeouts
                    }
                }
            }
        }
示例#2
0
        private static ChannelFactory <T> CreateChannelFactory <T>(string destino)
        {
            try
            {
                string          uri             = WCFHelper.GetServiceUrl(destino);
                EndpointAddress endpointAddress = new EndpointAddress(uri);
                WebHttpBinding  webHttpBinding  = WCFHelper.CreateWebHttpBinding(uri);

                ChannelFactory <T> channelFactory = new ChannelFactory <T>();
                channelFactory.Endpoint.Behaviors.Add(new WebHttpBehavior());
                channelFactory.Endpoint.Binding = webHttpBinding;
                channelFactory.Endpoint.Address = endpointAddress;

                return(channelFactory);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }