Alex_KD - 10 points!
Сказал Visual Studio "Generate async. calls", написал вот такой код - работает!
Код:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace VendGroupUpdate
{
class Program
{
static void Main(string[] args)
{
VendGroupService.CallContext context = new VendGroupService.CallContext();
VendGroupService.EntityKey[] keys;
VendGroupService.KeyField keyField;
VendGroupService.AxdVendGroup vendGroup;
DateTime timeNow;
IAsyncResult result;
int i;
AsyncCallback cb = new AsyncCallback(Program.VendGroupCallback);
;
context.Company = "USMF";
for (i = 1; i <= 1000; i++) // Try 1000 parallel calls
{
VendGroupService.VendGroupServiceClient client = new VendGroupService.VendGroupServiceClient();
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Anonymous;
keys = new VendGroupService.EntityKey[1];
keys[0] = new VendGroupService.EntityKey();
keyField = new VendGroupService.KeyField();
keyField.Field = "VendGroup";
keyField.Value = "10";
keys[0].KeyData = new VendGroupService.KeyField[1] { keyField };
vendGroup = new VendGroupService.AxdVendGroup();
vendGroup.VendGroup = new VendGroupService.AxdEntity_VendGroup[1];
vendGroup.VendGroup[0] = new VendGroupService.AxdEntity_VendGroup();
vendGroup.VendGroup[0].VendGroup = "10";
vendGroup.VendGroup[0].Name = i + " " + System.DateTime.Now.ToShortTimeString();
vendGroup.VendGroup[0]._DocumentHash = "XYZ";
vendGroup.VendGroup[0].action = VendGroupService.AxdEnum_AxdEntityAction.replace;
try
{
timeNow = System.DateTime.Now;
Console.WriteLine("Start call " + i);
//client.update(context, keys, vendGroup);
result = client.Beginupdate(context, keys, vendGroup, null/*cb*/, client);
Console.WriteLine("Call ended. Acknowledge: " + result.AsyncState.ToString());
Console.WriteLine("Delay: " + (-timeNow.Subtract(System.DateTime.Now)).ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
client.Abort();
}
//client.Close();
}
Console.ReadKey();
}
public static void VendGroupCallback(IAsyncResult ar)
{
VendGroupService.VendGroupServiceClient client = (VendGroupService.VendGroupServiceClient) ar.AsyncState;
client.Endupdate(ar);
Console.WriteLine("Callback fired.");
}
}
}
На самом деле это - симуляция, конечно. На сервер отправляется Request, .NET держит сессию и делает где-то в своих глубинах цикл, потом вызывает функцию Callback по указателю, передавая ей Response.