WCF 서비스가 FTP 프로토콜 (Linux 서버)을 통해 원격으로 액세스해야하는 FTP 서버와 Windows 클라이언트 응용 프로그램 간의 게이트웨이 역할을하는 솔루션을 구축 중입니다. 서비스 자체는 Windows IIS 서버에서 호스팅됩니다. 원격 FTP 서버에서 WCF로 파일 다운로드 및 스트리밍
나는 WCF를 사용하여 HTTP를 통해 파일을 스트리밍에 대한 기사에 내 모델을 기반으로하지만, 문제는 다음과 같습니다내가 클라이언트에와있는 윈도우 서버에 전에 먼저 straming을 다운로드 할 파일을 기다릴 필요가 주요 성능 문제가 될 수 있습니다. FTP Sever에서 클라이언트로 파일을 먼저 다운로드 할 필요없이 스트리밍하려고합니다.
// start service client
FileTransferClient.TransferServiceClient client = new FileTransferClient.TransferServiceClient();
LogText("Start");
// kill target file, if already exists
string filePath = System.IO.Path.Combine("Download", textBox1.Text);
if (System.IO.File.Exists(filePath)) System.IO.File.Delete(filePath);
// get stream from server
System.IO.Stream inputStream;
string fileName = textBox1.Text;
long length = client.DownloadFile(ref fileName, out inputStream);
// write server stream to disk
using (System.IO.FileStream writeStream = new System.IO.FileStream(filePath, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write))
{
int chunkSize = 2048;
byte[] buffer = new byte[chunkSize];
do
{
// read bytes from input stream
int bytesRead = inputStream.Read(buffer, 0, chunkSize);
if (bytesRead == 0) break;
// write bytes to output stream
writeStream.Write(buffer, 0, bytesRead);
// report progress from time to time
progressBar1.Value = (int)(writeStream.Position * 100/length);
} while (true);
// report end of progress
LogText("Done!");
writeStream.Close();
}
// close service client
inputStream.Dispose();
client.Close();
당신은 어떻게 생각하십니까 : 여기
는 ..public class TransferService : ITransferService{
Starksoft.Net.Ftp.FtpClient ftp = new Starksoft.Net.Ftp.FtpClient();
public RemoteFileInfo DownloadFile(DownloadRequest request)
{
RemoteFileInfo result = new RemoteFileInfo();
try
{
string filePath = System.IO.Path.Combine(@"C:\UploadFiles\ServerDownloadFiles", request.FileName);
System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
ftp = new Starksoft.Net.Ftp.FtpClient("127.0.0.1"); //remote ftp address
ftp.Open("user", "pass");
// here is waiting for the file to get downloaded from ftp server
System.IO.FileStream stream = new System.IO.FileStream(filePath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
ftp.GetFileAsync(request.FileName, stream, true);
stream.Close();
stream.Dispose();
// this will read and be streamed to client
System.IO.FileStream stream2 = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
result.FileName = request.FileName;
result.Length = stream2.Length;
result.FileByteStream = stream2;
}
catch (Exception ex)
{
}
return result;
}
이 같은 클라이언트 코드입니까?
2를 가지고 :
Stream stream;
public Stream GetStream(string filename)
{
Starksoft.Net.Ftp.FtpClient ftp = new Starksoft.Net.Ftp.FtpClient();
//string filePath = System.IO.Path.Combine(@"C:\UploadFiles\ServerDownloadFiles", filename);
//System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
ftp = new Starksoft.Net.Ftp.FtpClient("127.0.0.1");
ftp.Open("testuser", "123456");
stream = new MemoryStream();
ftp.GetFileAsyncCompleted += new EventHandler<Starksoft.Net.Ftp.GetFileAsyncCompletedEventArgs>(ftp_GetFileAsyncCompleted);
this.IsBusy = true;
ftp.GetFileAsync(filename, stream, true);
return stream;
}
서비스 계약 :
이[ServiceContract]
public interface IStreamingService
{
[OperationContract]
Stream GetStream(string filename);
[OperationContract]
Boolean GetBusyState();
}
서비스 구성 (바인딩) :
<basicHttpBinding>
<binding name="TransferService" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None">
</security>
</binding>
</basicHttpBinding>
나는 아름답게 작동한다고 생각합니다. 어느 쪽이든, 또는 시도하지 않았거나 문제가 무엇인지 알려주지 않았습니다. –
참고 사항 : 스트림 처리를 처리하려면'using' 문을 사용하는 것이 좋습니다. –