XML-RPC C#和Python RPC服务器
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了XML-RPC C#和Python RPC服务器,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2128字,纯文字阅读大概需要4分钟。
内容图文
![XML-RPC C#和Python RPC服务器](/upload/InfoBanner/zyjiaocheng/823/0b8f84a522094224b1b70a07f2e00fe1.jpg)
在我的服务器上,我使用Python的标准示例(使用额外的Hello World方法),在客户端,我使用C#中的XML-RPC.NET库.
但每次我运行我的客户端时,我都会得到一个例外,即找不到该方法.任何想法如何解决.
谢谢!
Python:
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)
# Create server
server = SimpleXMLRPCServer(("", 8000),
requestHandler=RequestHandler)
server.register_introspection_functions()
# Register pow() function; this will use the value of
# pow.__name__ as the name, which is just 'pow'.
server.register_function(pow)
# Register a function under a different name
def adder_function(x,y):
return x + y
server.register_function(adder_function, 'add')
def HelloWorld():
return "Hello Henrik"
server.register_function(HelloWorld,'HelloWorld')
# Register an instance; all the methods of the instance are
# published as XML-RPC methods (in this case, just 'div').
class MyFuncs:
def div(self, x, y):
return x // y
server.register_instance(MyFuncs())
# Run the server's main loop
server.serve_forever()
C#
namespace XMLRPC_Test
{
[XmlRpcUrl("http://188.40.xxx.xxx:8000")]
public interface HelloWorld : IXmlRpcProxy
{
[XmlRpcMethod]
String HelloWorld();
}
[XmlRpcUrl("http://188.40.xxx.xxx:8000")]
public interface add : IXmlRpcProxy
{
[XmlRpcMethod]
int add(int x, int y);
}
[XmlRpcUrl("http://188.40.xxx.xxx:8000")]
public interface listMethods : IXmlRpcProxy
{
[XmlRpcMethod("system.listMethods")]
String listMethods();
}
class Program
{
static void Main(string[] args)
{
listMethods proxy = XmlRpcProxyGen.Create<listMethods>();
Console.WriteLine(proxy.listMethods());
Console.ReadLine();
}
}
}
解决方法:
如果您将声明更改为此可行吗?
[XmlRpcUrl("http://188.40.xxx.xxx:8000/RPC2")]
SimpleXMLRPCRequestHandler.rpc_paths
An attribute value that must be a tuple listing valid path portions of the URL for receiving XML-RPC requests. Requests posted to other paths will result in a 404 “no such page” HTTP error. If this tuple is empty, all paths will be considered valid. The default value is (‘/’, ‘/RPC2’).
内容总结
以上是互联网集市为您收集整理的XML-RPC C#和Python RPC服务器全部内容,希望文章能够帮你解决XML-RPC C#和Python RPC服务器所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。