Beispiel #1
0
 protected void OpenChannel()
 {
     if (downloadChannel == null || !(downloadChannel.State == CommunicationState.Opened))
     {
         BasicHttpBinding downloadBinding = GetBasicHttpStreamBinding();
         EndpointAddress  address         = new EndpointAddress(string.Format("http://localhost/webservices/CoreService2011.svc/streamDownload_basicHttp", Environment.MachineName));
         downloadChannel = new StreamDownloadClient(downloadBinding, address);
     }
     downloadChannel.Open();
 }
Beispiel #2
0
        /// <summary>
        /// Upload a file to Tridion from a Tridion multimedia component or binary TBB
        /// </summary>
        /// <param name="item"><see cref="T:EGIT.CCIT.Tridion.CoreService.TcmUri"/> of the binary Tridion item.</param>
        /// <returns><see cref="T:System.IO.Stream" /> containing the binary data from Tridion</returns>
        public Stream DownloadFile(TcmUri item)
        {
            StreamDownloadClient client = null;

            try
            {
                client = DownloadClient;
                return(client.DownloadBinaryContent(item));
            }
            finally
            {
                if (client != null)
                {
                    if (client.State == CommunicationState.Faulted)
                    {
                        client.Abort();
                    }
                    else
                    {
                        client.Close();
                    }
                }
            }
        }
        public static StreamDownloadClient GetStreamDownloadClient(string host, string username, string password)
        {
            if (String.IsNullOrEmpty(host))
                host = "localhost";

            host = host.GetDomainNameAndPort();

            var binding = GetHttpBinding2();

            var endpoint = new EndpointAddress(String.Format("http://{0}/webservices/CoreService{1}.svc/streamDownload_basicHttp", host, ClientVersion));

            StreamDownloadClient client = new StreamDownloadClient(binding, endpoint);

            if (!String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(password))
            {
                client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
                client.ClientCredentials.Windows.ClientCredential = new NetworkCredential(username, password);
            }

            return client;
        }
 private static void EnsureValidStreamDownloadClient(MappingInfo mapping)
 {
     if (StreamDownloadClient == null || StreamDownloadClient.InnerChannel.State == CommunicationState.Faulted)
     {
         StreamDownloadClient = GetStreamDownloadClient(mapping);
     }
 }
 public static void ResetDownloadClient()
 {
     StreamDownloadClient = null;
 }