public UPnPInvokeException(string Method_Name, UPnPArgument[] Args, String msg, UPnPCustomException e)
     : base(msg)
 {
     MethodName = Method_Name;
     Arguments = Args;
     _Inner = e;
 }
 /// <summary>
 /// This is used to complete an AsyncRequest in an AsyncFashion.
 /// <para>
 /// You must either assign all the Argument values, or return an exception with "e"
 /// </para>
 /// </summary>
 /// <param name="id">ID</param>
 /// <param name="RetArg">Return Argument</param>
 /// <param name="OutArgs">Out Arguments</param>
 /// <param name="e">Exception</param>
 public void DelayedInvokeResponse(long id, object RetArg, UPnPArgument[] OutArgs, UPnPCustomException e)
 {
     UPnPDevice.InvokerInfoStruct iis = (UPnPDevice.InvokerInfoStruct)DelayedResponseTable[id];
     HTTPMessage resp = new HTTPMessage();
     if (e != null)
     {
         resp.StatusCode = 500;
         resp.StatusData = "Internal";
         resp.StringBuffer = ParentDevice.BuildErrorBody(e);
     }
     else
     {
         resp = ParentDevice.ParseInvokeResponse(iis.MethodName, iis.SOAPAction, this.ServiceURN, RetArg, OutArgs);
     }
     iis.WebSession.Send(resp);
     iis.WebSession.StartReading();
     lock (DelayedResponseTable)
     {
         DelayedResponseTable.Remove(id);
     }
 }
        private UPnPCustomException ParseErrorBody(String XML)
        {
            StringReader sr = new StringReader(XML);
            XmlTextReader XMLDoc = new XmlTextReader(sr);
            UPnPCustomException RetVal = null;

            int ec = 0;
            String ed = "";

            XMLDoc.Read();
            XMLDoc.MoveToContent();

            if (XMLDoc.LocalName == "Envelope")
            {
                XMLDoc.Read();
                XMLDoc.MoveToContent();
                while ((XMLDoc.LocalName != "Envelope") && (XMLDoc.EOF == false))
                {
                    switch (XMLDoc.LocalName)
                    {
                        case "Body":
                            XMLDoc.Read();
                            XMLDoc.MoveToContent();
                            while ((XMLDoc.LocalName != "Body") && (XMLDoc.EOF == false))
                            {
                                if (XMLDoc.LocalName == "Fault")
                                {
                                    XMLDoc.Read();
                                    XMLDoc.MoveToContent();
                                    while ((XMLDoc.LocalName != "Fault") && (XMLDoc.EOF == false))
                                    {
                                        switch (XMLDoc.LocalName)
                                        {
                                            case "detail":
                                                XMLDoc.Read();
                                                XMLDoc.MoveToContent();
                                                while ((XMLDoc.LocalName != "detail") && (XMLDoc.EOF == false))
                                                {
                                                    if (XMLDoc.LocalName == "UPnPError")
                                                    {
                                                        XMLDoc.Read();
                                                        XMLDoc.MoveToContent();
                                                        while ((XMLDoc.LocalName != "UPnPError") && (XMLDoc.EOF == false))
                                                        {
                                                            switch (XMLDoc.LocalName)
                                                            {
                                                                case "errorCode":
                                                                    ec = int.Parse(XMLDoc.ReadString());
                                                                    break;
                                                                case "errorDescription":
                                                                    ed = XMLDoc.ReadString();
                                                                    break;
                                                            }
                                                            XMLDoc.Read();
                                                            XMLDoc.MoveToContent();
                                                        }

                                                        RetVal = new UPnPCustomException(ec, ed);
                                                    }
                                                    else
                                                    {
                                                        XMLDoc.Skip();
                                                    }
                                                    XMLDoc.Read();
                                                    XMLDoc.MoveToContent();
                                                }
                                                break;
                                            default:
                                                XMLDoc.Skip();
                                                break;
                                        }
                                        XMLDoc.Read();
                                        XMLDoc.MoveToContent();
                                    }

                                }
                                else
                                {
                                    XMLDoc.Skip();
                                }
                                XMLDoc.Read();
                                XMLDoc.MoveToContent();
                            }
                            break;
                        default:
                            XMLDoc.Skip();
                            break;
                    }
                    XMLDoc.Read();
                    XMLDoc.MoveToContent();
                }
            }
            return (RetVal);
        }
示例#4
0
        internal string BuildErrorBody(UPnPCustomException e)
        {
            System.Text.StringBuilder s = new System.Text.StringBuilder();

            s.Append("<s:Envelope\r\n");
            s.Append("   xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"\r\n");
            s.Append("   s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n");
            s.Append("   <s:Body>\r\n");
            s.Append("      <s:Fault>\r\n");
            s.Append("         <faultcode>s:Client</faultcode>\r\n");
            s.Append("         <faultstring>UPnPError</faultstring>\r\n");
            s.Append("            <detail>\r\n");
            s.Append("               <UPnPError xmlns=\"urn:schemas-upnp-org:control-1-0\">\r\n");
            s.Append("                  <errorCode>" + e.ErrorCode.ToString() + "</errorCode>\r\n");
            s.Append("                  <errorDescription>" + UPnPStringFormatter.EscapeString(e.ErrorDescription) + "</errorDescription>\r\n");
            s.Append("               </UPnPError>\r\n");
            s.Append("            </detail>\r\n");
            s.Append("      </s:Fault>\r\n");
            s.Append("   </s:Body>\r\n");
            s.Append("</s:Envelope>");
            return (s.ToString());
        }