public Notify InvokeRemotingMessage(string service, string operation, params object[] args) { var msg = new RemotingMessage(); msg.operation = operation; msg.destination = service; msg.headers["DSRequestTimeout"] = 60; msg.headers["DSId"] = RtmpUtil.RandomUidString(); msg.headers["DSEndpoint"] = "my-rtmps"; msg.body = args; msg.messageId = RtmpUtil.RandomUidString(); return(Invoke(msg)); }
/// <summary> /// Used to invoke a service which you don't know what it returns. /// </summary> /// <param name="service"></param> /// <param name="operation"></param> /// <param name="args"></param> /// <returns>ASObject body</returns> public object InvokeServiceUnknown(string service, string operation, params object[] args) { var msg = new RemotingMessage(); msg.operation = operation; msg.destination = service; msg.headers["DSRequestTimeout"] = 60; msg.headers["DSId"] = RtmpUtil.RandomUidString(); msg.headers["DSEndpoint"] = "my-rtmps"; msg.body = args; msg.messageId = RtmpUtil.RandomUidString(); string endpoint = service + "." + operation; var result = Host.Call(msg); if (result == null) { StaticLogger.Warning(string.Format("Invoking {0} returned null", endpoint)); return(null); } if (RtmpUtil.IsError(result)) { var error = RtmpUtil.GetError(result); var errordetail = error != null && error.faultDetail != null?string.Format(" [{0}]", error.faultDetail) : ""; var errorstr = error != null && error.faultString != null?string.Format(", {0}", error.faultString) : ""; StaticLogger.Warning(string.Format( "{0} returned an error{1}{2}", endpoint, errorstr, errordetail )); return(null); } var body = RtmpUtil.GetBodies(result).FirstOrDefault(); if (body == null) { StaticLogger.Debug(endpoint + " RtmpUtil.GetBodies returned null"); return(null); } return(body.Item1); }
protected Notify InvokeCommandMessage(string service, int operation, object body, string DSId) { var msg = new CommandMessage(); msg.operation = operation; msg.correlationId = ""; msg.timestamp = 0; msg.clientId = null; msg.timeToLive = 0; msg.messageId = RtmpUtil.RandomUidString(); msg.destination = service; msg.body = body; msg.SetHeader("DSId", DSId); msg.SetHeader("DSEndpoint", "my-rtmps"); return(Invoke(msg)); }
public T InvokeService <T>(string service, string operation, params object[] args) where T : class { var msg = new RemotingMessage(); msg.operation = operation; msg.destination = service; msg.headers["DSRequestTimeout"] = 60; msg.headers["DSId"] = RtmpUtil.RandomUidString(); msg.headers["DSEndpoint"] = "my-rtmps"; msg.body = args; msg.messageId = RtmpUtil.RandomUidString(); string endpoint = service + "." + operation; var result = Host.Call(msg); if (result == null) { StaticLogger.Warning(string.Format("Invoking {0} returned null", endpoint)); return(null); } if (RtmpUtil.IsError(result)) { var error = RtmpUtil.GetError(result); var errordetail = error != null && error.faultDetail != null?string.Format(" [{0}]", error.faultDetail) : ""; var errorstr = error != null && error.faultString != null?string.Format(", {0}", error.faultString) : ""; StaticLogger.Warning(string.Format( "{0} returned an error{1}{2}", endpoint, errorstr, errordetail )); return(null); } var body = RtmpUtil.GetBodies(result).FirstOrDefault(); if (body == null) { StaticLogger.Debug(endpoint + " RtmpUtil.GetBodies returned null"); return(null); } if (body.Item1 == null) { StaticLogger.Debug(endpoint + " Body.Item1 returned null"); return(null); } object obj = null; if (body.Item1 is ASObject) { var ao = (ASObject)body.Item1; obj = MessageTranslator.Instance.GetObject <T>(ao); if (obj == null) { StaticLogger.Debug(endpoint + " expected " + typeof(T) + ", got " + ao.TypeName); return(null); } } else if (body.Item1 is ArrayCollection) { try { obj = Activator.CreateInstance(typeof(T), (ArrayCollection)body.Item1); } catch (Exception ex) { StaticLogger.Warning(endpoint + " failed to construct " + typeof(T)); StaticLogger.Debug(ex); return(null); } } else { StaticLogger.Debug(endpoint + " unknown object " + body.Item1.GetType()); return(null); } if (obj is MessageObject) { ((MessageObject)obj).TimeStamp = body.Item2; } return((T)obj); }