private void BriefAction(XmlReader reader, ServiceAction action) { reader.Read (); foreach (Argument argument in action.Arguments.Values) { argument.Value = argument.RelatedStateVariable.DefaultValue; } while (Helper.ReadToNextElement (reader)) { if (!action.Arguments.ContainsKey (reader.Name)) { throw UpnpControlException.InvalidArgs (); } Argument argument = action.Arguments[reader.Name]; if (argument.RelatedStateVariable.DataType.IsEnum) { try { argument.Value = Enum.Parse (argument.RelatedStateVariable.DataType, reader.ReadString ()); } catch { throw UpnpControlException.ArgumentValueOutOfRange (); } } else { try { argument.Value = Convert.ChangeType (reader.ReadString (), argument.RelatedStateVariable.DataType); } catch { throw UpnpControlException.InvalidArgs (); } // TODO handle min, max, and step } } reader.Close (); }
private void DebriefAction(HttpListenerContext context, ServiceAction action) { context.Response.ContentType = @"text/xml; charset=""utf-8"""; context.Response.Headers.Add ("Date", DateTime.Now.ToString ("r")); context.Response.Headers.Add ("EXT:"); context.Response.AddHeader ("SERVER", ServerString); Stream stream = context.Response.OutputStream; XmlWriterSettings settings = new XmlWriterSettings (); settings.Encoding = Encoding.UTF8; XmlWriter writer = XmlWriter.Create (stream, settings); Helper.WriteStartSoapBody (writer); writer.WriteStartElement (action.Name + "Response", action.Service.Type.ToString ()); foreach (Argument argument in action.Arguments.Values) { if (argument.Direction == ArgumentDirection.Out) { DebriefArgument (writer, argument); } } if (action.ReturnArgument != null) { DebriefArgument (writer, action.ReturnArgument); } writer.WriteEndElement (); Helper.WriteEndSoapBody (writer); writer.Flush (); context.Response.ContentLength64 = stream.Length; }