Exemple #1
0
    public void Write( XmlRpcException e )
    {
      if(e == null)
      {
        throw new ArgumentNullException("e", "Argument cannot be null");
      }

      WriteStartDocument();
      WriteMethodResponse();
      WriteStartElement( "fault" );
      XmlRpcStruct s = new XmlRpcStruct();
      s.Add( "faultCode", e.FaultCode );
      s.Add( "faultString", e.Message );
      WriteValue( s );
      WriteEndElement();
      WriteEndDocument();
    }
    public void Write( XmlRpcException e )
    {
      if(e == null)
      {
        throw new ArgumentNullException("e", "Argument cannot be null");
      }

      WriteStartDocument();
      WriteMethodResponse();
      WriteStartElement( "fault" );
      XmlRpcStruct s = new XmlRpcStruct();
      s.Add( "faultCode", e.FaultCode );
      s.Add( "faultString", e.Message );
      WriteValue( s );
      WriteEndElement();
      WriteEndDocument();
    }
Exemple #3
0
        public Object[] Invoke(String method_name, Object[] args)
        {
            if (method_name == null)
            {
                throw new ArgumentNullException("method_name", "Argument must not be null");
            }

            if (args == null)
            {
                throw new ArgumentNullException("args", "Argument must not be null");
            }

            MemoryStream        ms     = new MemoryStream();
            MethodCallFormatter call   = new MethodCallFormatter();
            XmlRpcMethod        method = new XmlRpcMethod(method_name);

            foreach (object obj in args)
            {
                method.Add(obj);
            }

            call.Serialize(ms, method);
            ms.Seek(0, 0);

            WebRequest wr = WebRequest.Create(Url);

            wr.Method        = "POST";
            wr.ContentLength = ms.Length;
            wr.Credentials   = Credentials;

            ns = wr.GetRequestStream();

            // Got stream to send (ms)
            int len = 1024;
            int bread;

            byte[] buffer = new byte[len];
            while ((bread = ms.Read(buffer, 0, len)) > 0)
            {
//String s = Encoding.ASCII.GetString(buffer, 0, bread );
//Console.Write( "{0}", s );
                ns.Write(buffer, 0, bread);
            }
            ns.Close();
            ns = (wr.GetResponse()).GetResponseStream();

//while( (bread = ns.Read(buffer, 0, len)) > 0) {
//String s = Encoding.ASCII.GetString(buffer, 0, bread );
//Console.Write( "{0}", s );
//			}

            // Get Response
            MethodResponseFormatter response = new MethodResponseFormatter();
            XmlRpcResponse          r        = (XmlRpcResponse)response.Deserialize(ns);

            ns.Close();
            Object[] results = r.ToArray();

            // Handle Fault responses
            if (results.Length > 0 &&
                results[0].GetType().ToString() == "DotGNU.XmlRpc.XmlRpcStruct")
            {
                XmlRpcStruct f = (XmlRpcStruct)results[0];

                if (f.ContainsKey("faultCode"))
                {
                    throw new XmlRpcException((int)f["faultCode"],
                                              (string)f["faultString"]);
                }
            }

            return(results);
        }
    private void WriteStruct( XmlRpcStruct v )
    {
      WriteStartElement( "struct" );
      
      foreach( DictionaryEntry entry in v ) {
	WriteStartElement( "member" );
	WriteElementString( "name", (string)entry.Key );
	WriteValue( entry.Value );
	WriteEndElement(); // member
      }
      WriteEndElement(); // struct
    }