There is the following task: Implement WCF service (inside the service several generalized queues turn in which typed Call objects are placed — by calling the service, each Call object has an Execute method making a request to the external API and returning a response in the form of a callback).
contract implementation
public class EDA : IEDA { private static List<ExchangeCallbackMessage> callbackMessages = new List<ExchangeCallbackMessage>(); private readonly Middlewaire<PoloExchange> poloPipeline = new Middlewaire<PoloExchange>(Configs.GetApiToken("polo")); //public EDA() //{ // callbackMessages = new List<ExchangeCallbackMessage>(); // poloPipeline = new Middlewaire<PoloExchange>(Configs.GetApiToken("polo")); //} public async Task<string> ReturnAddressAsync(string exchangeId, string currencyId) { poloPipeline.Callback += ExchangeMessageReceiver; var callParams = new CallParams(currId : currencyId); if (exchangeId == "polo") { var addressCall = new CallGetAddress<PoloExchange>(ref callParams); await poloPipeline.AddCallAsync(addressCall); } return callbackMessages.FirstOrDefault(m => m.CallId == callParams.CallId).Address; } private static void ExchangeMessageReceiver(ExchangeCallbackMessage message) { callbackMessages.Add(message); } } queue implementation
public class Middlewaire<T> where T : class, IExchange, new() { internal readonly T exchangeClient; private Queue<Call<T>> Processor { get; set; } public event ExchangeHandler Callback; public void CallbackAction(ExchangeCallbackMessage callbackMessage) => Callback?.Invoke(callbackMessage); public Middlewaire(ApiToken credential) { exchangeClient = new T(); exchangeClient.Initialize(credential); Processor = new Queue<Call<T>>(); var tm = new TimerCallback(TactAction); var timer = new Timer(tm, new object(), 0, 167); } public void TactAction(object obj) { //var processor = obj as Queue<Call<T>>; while (true) { if (Processor.Count != 0) { CallbackAction(Processor.Dequeue().Execute(exchangeClient)); } else continue; } } public async Task AddCallAsync(Call<T> call) => await Task.Run(() => Processor.Enqueue(call)); } The sequence of actions is as follows:
- An external application jerks the necessary contract and transmits to it a certain data set (two lines).
- On the basis of these lines, we create a typed
Call, select the necessary queue and putCallinto it. - The queue during the next clock cycle calls the
Callobject'sExecutemethod, which makes a request to the external API. - API gives the answer, which is in the form of a callback, returns it to the contract, where it is in turn processed and sent to an external application.
The service starts and works stably, but when I want to pull the contract, it is not executed. During the debug, I see that the execution thread re-creates the queue enters the loop and is spinning there until it issues a timeout error:
System.AggregateException HResult=0x80131500 Message=One or more errors occurred. (The request channel timed out attempting to send after 00:01:00. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.) Source=System.Private.CoreLib StackTrace: at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at EdaCoreTest.Program.GetRestr(EDAClient client) in D:\Work Folder\Test_C#_project\EdaCoreTest\EdaCoreTest\Program.cs:line 29 at EdaCoreTest.Program.Main(String[] args) in D:\Work Folder\Test_C#_project\EdaCoreTest\EdaCoreTest\Program.cs:line 14 Inner Exception 1: TimeoutException: The request channel timed out attempting to send after 00:01:00. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout. Inner Exception 2: TimeoutException: The HTTP request to 'http://localhost:58995/EDA.svc' has exceeded the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout. Maybe I do not fully understand the technology of WCF, or some kind of error in the architecture or something else. In general, I hope for an independent assessment of the situation from the outside.