Пример #1
0
 private void BeginResponseFlexCall(IAsyncResult ar)
 {
     try
     {
         AmfRequestData amfRequestData = ar.AsyncState as AmfRequestData;
         if (amfRequestData != null)
         {
             HttpWebResponse response = (HttpWebResponse)amfRequestData.Request.EndGetResponse(ar);
             if (response != null)
             {
                 //Get response and deserialize
                 Stream responseStream = response.GetResponseStream();
                 if (responseStream != null)
                 {
                     AMFDeserializer amfDeserializer = new AMFDeserializer(responseStream);
                     AMFMessage responseMessage = amfDeserializer.ReadAMFMessage();
                     AMFBody responseBody = responseMessage.GetBodyAt(0);
                     for (int i = 0; i < responseMessage.HeaderCount; i++)
                     {
                         AMFHeader header = responseMessage.GetHeaderAt(i);
                         if (header.Name == AMFHeader.RequestPersistentHeader)
                             _netConnection.AddHeader(header.Name, header.MustUnderstand, header.Content);
                     }
                     object message = responseBody.Content;
                     if (message is ErrorMessage)
                     {
                         /*
                         ASObject status = new ASObject();
                         status["level"] = "error";
                         status["code"] = "NetConnection.Call.Failed";
                         status["description"] = (result as ErrorMessage).faultString;
                         status["details"] = result;
                         _netConnection.RaiseNetStatus(status);
                         */
                         if (amfRequestData.Call != null)
                         {
                             PendingCall call = amfRequestData.Call;
                             call.Result = message;
                             call.Status = Messaging.Rtmp.Service.Call.STATUS_INVOCATION_EXCEPTION;
                             amfRequestData.Callback.ResultReceived(call);
                         }
                         if (amfRequestData.Responder != null)
                         {
                             StatusFunction statusFunction = amfRequestData.Responder.GetType().GetProperty("Status").GetValue(amfRequestData.Responder, null) as StatusFunction;
                             if (statusFunction != null)
                                 statusFunction(new Fault(message as ErrorMessage));
                         }
                     }
                     else if (message is AcknowledgeMessage)
                     {
                         AcknowledgeMessage ack = message as AcknowledgeMessage;
                         if (_netConnection.ClientId == null && ack.HeaderExists(MessageBase.FlexClientIdHeader))
                             _netConnection.SetClientId(ack.GetHeader(MessageBase.FlexClientIdHeader) as string);
                         if (amfRequestData.Call != null)
                         {
                             PendingCall call = amfRequestData.Call;
                             call.Result = ack.body;
                             call.Status = Messaging.Rtmp.Service.Call.STATUS_SUCCESS_RESULT;
                             amfRequestData.Callback.ResultReceived(call);
                         }
                         if (amfRequestData.Responder != null)
                         {
                             Delegate resultFunction = amfRequestData.Responder.GetType().GetProperty("Result").GetValue(amfRequestData.Responder, null) as Delegate;
                             if (resultFunction != null)
                             {
                                 ParameterInfo[] arguments = resultFunction.Method.GetParameters();
                                 object result = TypeHelper.ChangeType(ack.body, arguments[0].ParameterType);
                                 resultFunction.DynamicInvoke(result);
                             }
                         }
                     }
                 }
                 else
                     _netConnection.RaiseNetStatus("Could not aquire ResponseStream");
             }
             else
                 _netConnection.RaiseNetStatus("Could not aquire HttpWebResponse");
         }
     }
     catch (Exception ex)
     {
         _netConnection.RaiseNetStatus(ex);
     }
 }
Пример #2
0
 private void BeginResponseFlexCall(IAsyncResult ar)
 {
     try
     {
         RequestData asyncState = ar.AsyncState as RequestData;
         if (asyncState != null)
         {
             HttpWebResponse response = (HttpWebResponse)asyncState.Request.EndGetResponse(ar);
             if (response != null)
             {
                 Stream responseStream = response.GetResponseStream();
                 if (responseStream != null)
                 {
                     PendingCall call;
                     AMFMessage  message = new AMFDeserializer(responseStream).ReadAMFMessage();
                     AMFBody     bodyAt  = message.GetBodyAt(0);
                     for (int i = 0; i < message.HeaderCount; i++)
                     {
                         AMFHeader headerAt = message.GetHeaderAt(i);
                         if (headerAt.Name == "RequestPersistentHeader")
                         {
                             this._netConnection.AddHeader(headerAt.Name, headerAt.MustUnderstand, headerAt.Content);
                         }
                     }
                     object content = bodyAt.Content;
                     if (content is ErrorMessage)
                     {
                         call        = asyncState.Call;
                         call.Result = content;
                         call.Status = 0x13;
                         asyncState.Callback.ResultReceived(call);
                     }
                     if (content is AcknowledgeMessage)
                     {
                         AcknowledgeMessage message2 = content as AcknowledgeMessage;
                         if ((this._netConnection.ClientId == null) && message2.HeaderExists("DSId"))
                         {
                             this._netConnection.SetClientId(message2.GetHeader("DSId") as string);
                         }
                         call        = asyncState.Call;
                         call.Result = message2.body;
                         call.Status = 2;
                         asyncState.Callback.ResultReceived(call);
                     }
                 }
                 else
                 {
                     this._netConnection.RaiseNetStatus("Could not aquire ResponseStream");
                 }
             }
             else
             {
                 this._netConnection.RaiseNetStatus("Could not aquire HttpWebResponse");
             }
         }
     }
     catch (Exception exception)
     {
         this._netConnection.RaiseNetStatus(exception);
     }
 }