いくつかのことを試すことができます。使用しているプロトコルやホスティング方法については言及していないので、IIS7 と SOAP を使用している可能性があると想定します。Web サービスの web.config ファイルに次を追加すると、404 エラーなしで転送できるファイル サイズを増やすことができます。
<system.web>
<httpRuntime executionTimeout="999999" maxRequestLength="2097151" />
...
</system.web>
大きなファイルの転送を許可するために、Web サービスの web.config ファイルに対して行う必要がある 2 番目のこと:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2000000000" />
</requestFiltering>
</security>
</system.webServer>
別の可能性:
<location path="Copy.asmx"> <!-- Name of you asmx -->
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="104857600"/> <!-- 100 megs -->
</requestFiltering>
</security>
</system.webServer>
</location>
byte[] を Web サービス経由で送信する際の主な問題は、base 64 文字列としてエンコードされる SOAP 本文に入れられることです。このようにファイルをエンコードすると、soap 本体でファイルのサイズが 3 分の 2 も大きくなります (つまり、6 MB のファイルがネットワーク経由で 9 MB のファイルになります)。
もう1つの可能性は、送信前にデータを小さなセグメントに分割する「チャンク」です。これで十分かもしれません。チャンク サイズ (500KB に設定) は、ネットワーク速度、サーバー リソースなどの要因に基づいて、アップロードのパフォーマンスを向上させる重要な要因になる可能性があります。
/// <summary>
/// Chunk the file and upload
/// </summary>
/// <param name="filename"></param>
private void UploadVideo(string filename)
{
#region Vars
const int chunkSize = 512000;
byte[] bytes = null;
int startIndex, endIndex, length, totalChunks;
WS.UploadRequest objRequest = new WS.UploadRequest();
#endregion
try
{
if (File.Exists(filename))
{
using (WS.UploadService objService = new WS.UploadService())
{
using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
{
//// Calculate total chunks to be sent to service
totalChunks = (int)Math.Ceiling((double)fs.Length / chunkSize);
//// Set up Upload request object
objRequest.FileName = filename;
objRequest.FileSize = fs.Length;
for (int i = 0; i < totalChunks; i++)
{
startIndex = i * chunkSize;
endIndex = (int)(startIndex + chunkSize > fs.Length ? fs.Length : startIndex + chunkSize);
length = endIndex - startIndex;
bytes = new byte[length];
//// Read bytes from file, and send upload request
fs.Read(bytes, 0, bytes.Length);
objRequest.FileBytes = bytes;
objService.UploadVideo(objRequest);
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(string.Format("Error- {0}", ex.Message));
}