protected byte[] CreateRequest(V3Message v3Msg, IDictionary headers) { Header[] headersArray = null; if (headers != null) { headersArray = new Header[headers.Count]; int i = 0; foreach (String headerName in headers.Keys) { headersArray[i] = new Header(headerName, false, -1, new ConcreteObject(headers[headerName])); } } else { headersArray = new Header[0]; } Body[] bodiesArray = new Body[1]; bodiesArray[0] = new Body("null", "null", -1, null); Request request = new Request(3, headersArray, bodiesArray); request.setResponseBodyData(new object[] { v3Msg }); return(AMFSerializer.SerializeToBytes(request)); }
public override async Task <T> SendRequest <T>(V3Message v3Msg, IDictionary requestHeaders, IDictionary httpHeaders, ResponseThreadConfigurator threadConfigurator) { return(await SendHttpRequest <T>(v3Msg, requestHeaders, httpHeaders, threadConfigurator)); }
private void ProcessAMFResponse <T>(IAsyncResult asyncResult) { try { AsyncStreamSetInfo <T> asyncStreamSetInfo = (AsyncStreamSetInfo <T>)asyncResult.AsyncState; if (asyncStreamSetInfo.responseThreadConfigurator != null) { asyncStreamSetInfo.responseThreadConfigurator(); } HttpWebRequest request = asyncStreamSetInfo.request; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult); if (Cookies != null) { foreach (Cookie cookie in response.Cookies) { Cookies.Add(new Uri(GatewayUrl), cookie); } } Stream streamResponse = response.GetResponseStream(); long curTime = DateTime.Now.Ticks; long roundTrip = (curTime - asyncStreamSetInfo.messageSentTime) / TimeSpan.TicksPerMillisecond; RequestParser parser = new RequestParser(); Request responseObject = parser.readMessage(streamResponse); object[] responseData = (object[])responseObject.getRequestBodyData(); V3Message v3 = (V3Message)((IAdaptingType)responseData[0]).defaultAdapt(); if (v3.isError) { ErrMessage errorMessage = (ErrMessage)v3; Fault fault = new Fault(errorMessage.faultString, errorMessage.faultDetail, errorMessage.faultCode); if (asyncStreamSetInfo.responder != null) { asyncStreamSetInfo.responder.ErrorHandler(fault); } return; } IAdaptingType body = (IAdaptingType)((AnonymousObject)((NamedObject)responseData[0]).TypedObject).Properties["body"]; T result = (T)body.adapt(typeof(T)); if (asyncStreamSetInfo.responder != null) { asyncStreamSetInfo.responder.ResponseHandler(result); } // ProcessV3Message( v3, asyncStreamSetInfo.responder ); } catch (Exception e) { AsyncStreamSetInfo <T> asyncStreamSetInfo = (AsyncStreamSetInfo <T>)asyncResult.AsyncState; ProccessException(e, asyncStreamSetInfo.responder); } }
public override void SendRequest <T>(V3Message v3Msg, IDictionary requestHeaders, IDictionary httpHeaders, Responder <T> responder, AsyncStreamSetInfo <T> asyncStreamSetInfo) { ThreadPool.QueueUserWorkItem(state => SendHttpRequest(v3Msg, requestHeaders, httpHeaders, responder, asyncStreamSetInfo)); }
private void SendHttpRequest <T>(V3Message v3Msg, IDictionary requestHeaders, IDictionary httpHeaders, Responder <T> responder, AsyncStreamSetInfo <T> asyncStreamSetInfo) { HttpWebRequest webReq; try { webReq = GetWebRequest(); } catch (Exception e) { HandleException(asyncStreamSetInfo, e); return; } if (httpHeaders != null) { foreach (DictionaryEntry header in httpHeaders) { webReq.Headers[header.Key.ToString()] = header.Value.ToString(); } } webReq.CookieContainer = Cookies; byte[] requestBytes = CreateRequest(v3Msg, requestHeaders); asyncStreamSetInfo.requestBytes = requestBytes; asyncStreamSetInfo.request = webReq; asyncStreamSetInfo.responder = responder; // Set the ContentType property. webReq.ContentType = "application/x-amf"; // Set the Method property to 'POST' to post data to the URI. webReq.Method = "POST"; // Start the asynchronous operation. try { webReq.BeginGetRequestStream(new AsyncCallback(SetStreamDataCallback <T>), asyncStreamSetInfo); } catch (Exception e1) { HandleException(asyncStreamSetInfo, e1); } }
internal void SendRequest <T>(V3Message v3Msg, Responder <T> responder) { SendRequest(v3Msg, null, null, responder, null); }
public abstract void SendRequest <T>(V3Message v3Msg, IDictionary requestHeaders, IDictionary httpHeaders, Responder <T> responder, AsyncStreamSetInfo <T> asyncStreamSetInfo);
public void SendMessage <T>(V3Message v3Msg, Responder <T> responder) { _engine.SendRequest(v3Msg, null, null, responder, null); }
public abstract Task <T> SendRequest <T>(V3Message v3Msg, IDictionary requestHeaders, IDictionary httpHeaders, ResponseThreadConfigurator threadConfigurator);
private async Task <T> SendHttpRequest <T>(V3Message v3Msg, IDictionary requestHeaders, IDictionary httpHeaders, ResponseThreadConfigurator threadConfigurator) { HttpWebRequest webReq; try { webReq = GetWebRequest(); } catch (Exception e) { throw new WebORBException(GetFault(e)); } if (httpHeaders != null) { foreach (DictionaryEntry header in httpHeaders) { webReq.Headers[header.Key.ToString()] = header.Value.ToString(); } } webReq.CookieContainer = Cookies; byte[] requestBytes = CreateRequest(v3Msg, requestHeaders); // Set the ContentType property. webReq.ContentType = "application/x-amf"; // Set the Method property to 'POST' to post data to the URI. webReq.Method = "POST"; // Start the asynchronous operation. Stream postStream = await webReq.GetRequestStreamAsync(); try { // End the operation. postStream.Write(requestBytes, 0, requestBytes.Length); postStream.Flush(); postStream.Close(); HttpWebResponse response = (HttpWebResponse)await webReq.GetResponseAsync(); threadConfigurator?.Invoke(); if (Cookies != null) { foreach (Cookie cookie in response.Cookies) { Cookies.Add(new Uri(GatewayUrl), cookie); } } var streamResponse = response.GetResponseStream(); var parser = new RequestParser(); var responseObject = parser.readMessage(streamResponse); var responseData = (object[])responseObject.getRequestBodyData(); var v3 = (V3Message)((IAdaptingType)responseData[0]).defaultAdapt(); if (v3.isError) { var errorMessage = (ErrMessage)v3; var fault = new Fault(errorMessage.faultString, errorMessage.faultDetail, errorMessage.faultCode); throw new WebORBException(fault); } var body = (IAdaptingType)((AnonymousObject)((NamedObject)responseData[0]).TypedObject).Properties["body"]; var result = (T)body.adapt(typeof(T)); return(result); } catch (Exception exception) { if (exception is WebORBException) { throw exception; } throw new WebORBException(GetFault(exception)); } }