filestream を使用してファイルにバイトを追加する際に問題に直面しています。ファイルのバイトを分割し、1 回の送信ではなく n 回で Web サービスに送信するクライアント アプリケーションがあります。
私のWebサービスコードは次のとおりです。
public bool TransferFile(byte[] bytes, ref string token, ref string path, string extension)
{
string folderPath = string.Empty;
if (System.Configuration.ConfigurationManager.AppSettings["DepositPath"] != null)
{
folderPath = System.Configuration.ConfigurationManager.AppSettings["DepositPath"].ToString();
}
if (string.IsNullOrEmpty(token))
{
token = Guid.NewGuid().ToString();
}
path = Path.Combine(folderPath, token + extension);
if (!File.Exists(path))
{
using (FileStream fs = File.Create(path)){
fs.Dispose();
}
}
using (FileStream stream = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.Write))
{
stream.Write(bytes, 0, bytes.Length);
stream.Flush();
stream.Close();
stream.Dispose();
}
return true;
}
ファイルを追加モードで開き、バイトを追加してストリームを閉じました。ファイルが他のプロセスによって使用されていることを示す IOException が発生したにもかかわらず。application-pool-identities も構成しました。この問題を解決するためのアイデアを提供してください。
System.Web.Services.Protocols.SoapException: サーバーは要求を処理できませんでした。---> System.IO.IOException: 別のプロセスで使用されているため、プロセスはファイル 'D:\Development Projects\IAM\FileTransporter\DepositFolder\79ede99d-d76a-4050-959d-17bb87fa6fdb.exe' にアクセスできません。 System.IO.__Error.WinIOError (Int32 errorCode、文字列の多分フルパス) で System.IO.FileStream.Init (文字列パス、FileMode モード、FileAccess アクセス、Int32 権限、ブール値の useRights、FileShare 共有、Int32 bufferSize、FileOptions オプション、SECURITY_ATTRIBUTES secAttrs , String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at FileTransporterService.Service.TransferFile(Byte[] bytes, String& token, String& path, String extension) D:\Development Projects\IAM\FileTransporter\FileTransporterService\Service.asmx.cs:36 行目 --- 内部例外スタック トレースの終わり ---