本文整理汇总了C#中Nwc.XmlRpc.XmlRpcRequest.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# XmlRpcRequest.Invoke方法的具体用法?C# XmlRpcRequest.Invoke怎么用?C# XmlRpcRequest.Invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nwc.XmlRpc.XmlRpcRequest
的用法示例。
在下文中一共展示了XmlRpcRequest.Invoke方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
/// <summary>Main application method.</summary>
/// <remarks> Simply sets up logging and then an <c>XmlRpcRequest</c> instance. Then
/// Calls <c>sample.Ping</c>, <c>sample.Echo</c> and <c>sample.Broken</c> in sequence.
/// The <c>XmlRpcResponse</c> from each call is then displayed. Faults are checked for.
/// </remarks>
public static void Main(String[] args)
{
if (args.Length == 1)
{
URL = args[0];
}
Console.WriteLine("Server: " + URL);
// Use the console logger above.
Logger.Delegate = new Logger.LoggerDelegate(WriteEntry);
// Send the sample.Ping RPC using the Send method which gives you a little more control...
XmlRpcRequest client = new XmlRpcRequest();
client.MethodName = "sample.Ping";
try
{
Console.WriteLine("Request: " + client);
XmlRpcResponse response = client.Send(URL, 10000);
Console.WriteLine("Response: " + response);
if (response.IsFault)
{
Console.WriteLine("Fault {0}: {1}", response.FaultCode, response.FaultString);
}
else
{
Console.WriteLine("Returned: " + response.Value);
}
}
catch (Exception e)
{
Console.WriteLine("Exception " + e);
}
// Invoke the sample.Echo RPC - Invoke more closely parallels a method invocation
client.MethodName = "sample.Echo";
client.Params.Clear();
client.Params.Add("Hello");
try
{
String echo = (String)client.Invoke(URL);
Console.WriteLine("Returned: " + echo);
}
catch (XmlRpcException serverException)
{
Console.WriteLine("Fault {0}: {1}", serverException.FaultCode, serverException.FaultString);
}
catch (Exception e)
{
Console.WriteLine("Exception " + e);
}
// Invoke sample.Broken RPC - method that is not present on server.
client.MethodName = "sample.Broken";
client.Params.Clear();
try
{
Object response = client.Invoke(URL);
Console.WriteLine("Response: " + response);
}
catch (XmlRpcException serverException)
{
Console.WriteLine("Fault {0}: {1}", serverException.FaultCode, serverException.FaultString);
}
catch (Exception e)
{
Console.WriteLine("Exception " + e);
}
}
示例2: Main
/// <summary>Submit two XML-RPC calls to Google. One to suggest spelling on a phrase and
/// the next to do a basic search.</summary>
public static void Main()
{
// Use the console logger above.
Logger.Delegate = new Logger.LoggerDelegate(WriteEntry);
// Send the sample.Ping RPC using the Send method which gives you a little more control...
XmlRpcRequest client = new XmlRpcRequest();
client.MethodName = SPELL_CHECK;
client.Params.Add(PHRASE);
client.Params.Add(KEY);
Console.WriteLine("Looking up: " + PHRASE);
try
{
Console.WriteLine("Request: " + client);
XmlRpcResponse response = client.Send(URL, 10000);
Console.WriteLine("Response: " + response);
if (response.IsFault)
{
Console.WriteLine("Fault {0}: {1}", response.FaultCode, response.FaultString);
}
else
{
Console.WriteLine("Returned: " + response.Value);
}
}
catch (XmlRpcException serverException)
{
Console.WriteLine("Fault {0}: {1}", serverException.FaultCode, serverException.FaultString);
}
catch (Exception e)
{
Console.WriteLine("Exception " + e);
}
client.MethodName = RESULTS;
client.Params.Clear();
client.Params.Add("C# XML-RPC .Net");
client.Params.Add(0);
client.Params.Add(5);
client.Params.Add("");
client.Params.Add("");
client.Params.Add(false);
client.Params.Add("");
client.Params.Add("");
client.Params.Add(KEY);
try
{
Hashtable results = (Hashtable)client.Invoke(URL);
foreach (Hashtable result in ((Hashtable)results["resultElements"]).Values)
{
Console.WriteLine("Title: {0}",result["title"]);
Console.WriteLine("URL: {0}",result["URL"]);
Console.WriteLine("Context: {0}",result["snippet"]);
Console.WriteLine("------------------------------------------------------------");
}
}
catch (XmlRpcException serverException)
{
Console.WriteLine("Fault {0}: {1}", serverException.FaultCode, serverException.FaultString);
}
catch (Exception e)
{
Console.WriteLine("Exception " + e);
}
}
示例3: Authenticate
///<summary>Sends request to MyPW and returns a result code</summary>
///<remarks>The result code will be:
/// <list type="bullet">
/// <item>-99999 = MAJOR ERROR - request couldn't be sent (networking problems?)</item>
/// <item>-99 = Site Authentication Failure (siteid/authkey)</item>
/// <item>-2 = Token disabled</item>
/// <item>-1 = Token not found. </item>
/// <item>0 = Sucess! Authenticated!</item>
/// <item>others = see message</item>
/// </list>
///</remarks>
public string Authenticate()
{
// client is the actual object that sends the request
XmlRpcRequest client = new XmlRpcRequest();
client.MethodName = "auth.auth"; // Set the XML RPC Method
client.Params.Clear(); // Make sure we remove all client data
client.Params.Add(this.request); // Now add our data
// try / catch -- this actuall sends the request to MyPW
try
{
this.results = (Hashtable)client.Invoke("https://services.mypw.com/RPC2");
}
catch (XmlRpcException serverException)
{
Console.WriteLine("[MyPWAuth] ERROR {0}: {1}", serverException.FaultCode, serverException.FaultString);
}
catch (Exception ex)
{
Console.WriteLine("[MyPWAuth] ERROR: " + ex.Message + " @ " + ex.TargetSite);
}
// try / catch -- return the result code as a string.
try
{
return (Convert.ToString(this.results["code"]));
}
catch (Exception ex)
{
Console.WriteLine("[MyPWAuth] ERROR: Response parse failure. No valid response. @ " + ex.TargetSite);
return ("-99999");