ID を文字列として送信する必要がある tcp it サービスを使用しようとしています。サンプルコードから以下のメソッドを取得しました。問題は、「4000」、「2000」、「3000」などの 4 文字の数字を含む文字列を入力するとメソッドは機能しますが、4 文字未満の文字列を入力すると「1」、「20」、または「300」になることです。戻り値
System.ArgumentException: 宛先配列の長さが十分ではありません。destIndex と長さ、および配列の下限を確認してください。
public byte[] prepNetworkStreamBuffer(string reqiiredID) {
byte[] id = UTF8Encoding.UTF8.GetBytes(reqiiredID);
int l = id.Length;
byte[] idb = BitConverter.GetBytes(System.Net.IPAddress.HostToNetworkOrder(l));
byte[] buff = new byte[1 + 1 + id.Length + l];
buff[0] = 0;
buff[1] = (byte)VerificationServiceCommands.addIDtoAFIS;
idb.CopyTo(buff, 1 + 1);
id.CopyTo(buff, 1 + 1 + idb.Length);
return buff;
}