Requestオブジェクトに関する
// Code snippet
public static List<X> GetCashBalances(List<Y> IPReceivedAtWebMethod)
{
List<X> list = new List<X>();
if IPReceivedAtWebMethod== null) return list;
if IPReceivedAtWebMethod.Count <= 0) return list;
// The below line throws Index out of range error.
SomeValue s = AdminHelper.GetSomeValue(IPReceivedAtWebMethod[0].member1);
// …
}
上記のメソッドを呼び出すWCFサービスメソッドは、参照のために以下の通りです
、
public class CashService : ICashService
{
public ServiceResponse GenerateCashBalances(RequestToWCFService request)
{
ServiceResponse response = DataContractFactory.InstanceOfServiceResponse();
try
{
// This is the code calling the method I referred in the question which is throwing Index out of range Error
response._someList = StaticClass.GetCashBalancesReferredInQuestion(request._someList);
// I hope this would not do any harm to _someList
List<CashBalance> list = response._someList.ConvertAll(c => (CashBalance)c);
// Second call using the same collection however the list is not alterned inside this method too.
response.someActivity = AdminController.GetActivity(request._someList).ToString("O");
response.ResponseCode = WcfServiceCodes.OK_RESPONSE;
}
catch (Exception ex)
{
// log error
}
return response;
}
詳細メソッドを呼び出すことによって使用されています。言うのは非常に簡単になるだろう:_someList
が異なる様々な方法で消費されますどこかの静的フィールドである
var balances = GetCashBalances(_someList);
...。何かが
_someList
から要素を削除した場合は、報告している問題が発生しがちです。この場合に役立ちます
参照:
var list = _someList.ToList(); // create a local copy.
var balances = GetCashBalances(list);
は、この状態(特にパラメータ)のいずれかが別の要求の間で共有されていますか? –
はい、ルートメソッドから2つのメソッドに同期して渡されます。私が他の答えで述べたように、私が行っている並列スレッド/非同期呼び出しはありません。 –