コード例 #1
0
    // Returns a XmlRpcMethod object from the incoming stream
    public object Deserialize( Stream stream )
    {
      XmlTextReader tr = new XmlTextReader( stream );
      XmlRpcMethod method = new XmlRpcMethod();
      method.Read( tr );

      return method;
    }
コード例 #2
0
    public void Write( XmlRpcMethod method )
    {
      if(method == null)
      {
        throw new ArgumentNullException("method", "Argument cannot be null");
      }

      WriteStartDocument();
      WriteStartElement( "methodCall" );
      WriteElementString( "methodName", method.Name );
      WriteParams();
      foreach( object o in method ) {
	WriteParam( o );
      }
      WriteEndDocument();
    }
コード例 #3
0
    public void Write( XmlRpcMethod method )
    {
      if(method == null)
      {
        throw new ArgumentNullException("method", "Argument cannot be null");
      }

      WriteStartDocument();
      WriteStartElement( "methodCall" );
      WriteElementString( "methodName", method.Name );
      WriteParams();
      foreach( object o in method ) {
	WriteParam( o );
      }
      WriteEndDocument();
    }
コード例 #4
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);
        }
コード例 #5
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;
		}