protected override void ProcessRequest(string path, Stream request, Stream responseStream, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { RestSessionObject <TRequest> deserial = default(RestSessionObject <TRequest>); bool fail = false; using (XmlTextReader xmlReader = new XmlTextReader(request)) { try { XmlSerializer deserializer = new XmlSerializer(typeof(RestSessionObject <TRequest>)); deserial = (RestSessionObject <TRequest>)deserializer.Deserialize(xmlReader); } catch (Exception e) { m_log.Error("[REST]: Deserialization problem. Ignoring request. " + e); fail = true; } } TResponse response = default(TResponse); if (!fail && m_smethod(deserial.SessionID, deserial.AvatarID)) { response = m_method(deserial.Body); } using (XmlWriter xmlWriter = XmlTextWriter.Create(responseStream)) { XmlSerializer serializer = new XmlSerializer(typeof(TResponse)); serializer.Serialize(xmlWriter, response); } }
public static TResponse BeginPostObject(string verb, string requestUrl, TRequest obj, string sid, string aid) { RestSessionObject <TRequest> sobj = new RestSessionObject <TRequest>(); sobj.SessionID = sid; sobj.AvatarID = aid; sobj.Body = obj; Type type = typeof(RestSessionObject <TRequest>); ServicePointManagerTimeoutSupport.ResetHosts(); WebRequest request = WebRequest.Create(requestUrl); request.Method = verb; request.ContentType = "text/xml"; request.Timeout = 20000; MemoryStream buffer = new MemoryStream(); XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = Encoding.UTF8; using (XmlWriter writer = XmlWriter.Create(buffer, settings)) { XmlSerializer serializer = new XmlSerializer(type); serializer.Serialize(writer, sobj); writer.Flush(); } int length = (int)buffer.Length; request.ContentLength = length; Stream requestStream = request.GetRequestStream(); requestStream.Write(buffer.ToArray(), 0, length); buffer.Close(); requestStream.Close(); TResponse deserial = default(TResponse); using (WebResponse resp = request.GetResponse()) { XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); using (Stream respStream = resp.GetResponseStream()) deserial = (TResponse)deserializer.Deserialize(respStream); } return(deserial); }
public void BeginPostObject(string verb, string requestUrl, TRequest obj, string sid, string aid) { RestSessionObject <TRequest> sobj = new RestSessionObject <TRequest>(); sobj.SessionID = sid; sobj.AvatarID = aid; sobj.Body = obj; Type type = typeof(RestSessionObject <TRequest>); ServicePointManagerTimeoutSupport.ResetHosts(); WebRequest request = WebRequest.Create(requestUrl); request.Method = verb; request.ContentType = "text/xml"; request.Timeout = 10000; MemoryStream buffer = new MemoryStream(); XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = Encoding.UTF8; using (XmlWriter writer = XmlWriter.Create(buffer, settings)) { XmlSerializer serializer = new XmlSerializer(type); serializer.Serialize(writer, sobj); writer.Flush(); } buffer.Close(); int length = (int)buffer.Length; request.ContentLength = length; Stream requestStream = request.GetRequestStream(); requestStream.Write(buffer.ToArray(), 0, length); requestStream.Close(); // IAsyncResult result = request.BeginGetResponse(AsyncCallback, request); request.BeginGetResponse(AsyncCallback, request); }