【发布时间】:2011-06-02 10:20:56
【问题描述】:
我在 Linux 机器(ubuntu)上创建了一个 Python 网络服务:
import soaplib
import os
from soaplib.core.service import rpc, DefinitionBase, soap
from soaplib.core.model.primitive import String, Integer
from soaplib.core.server import wsgi
from soaplib.core.model.clazz import Array
def runcmd(cmd):
fout = os.popen(cmd)
out = fout.read()
return out
class LinuxServices(DefinitionBase):
@soap(String, String,_returns=Array(String))
def df(self,server, user):
L = []
cmd = 'df -hP | grep "/"'
output = runcmd(cmd).split('\n')
for n in xrange(len(output)-1):
out = output[n].split()
L.append('%s;%s' % (out[5], out[4]))
return L
if __name__=='__main__':
try:
from wsgiref.simple_server import make_server
soap_application = soaplib.core.Application([LinuxServices], 'tns')
wsgi_application = wsgi.Application(soap_application)
server = make_server('0.0.0.0', 7789, wsgi_application)
server.serve_forever()
except ImportError:
print "Error: example server code requires Python >= 2.5"
我是根据这个例子创建的:soaplib helloworld
然后(在 Windows 7 上)我创建了一个 Silverlight 项目,我使用这个 ws 在我的 linux 服务器上获取磁盘状态:
Silverlight 项目中的服务:
public class LinuxService
{
[OperationContract]
public List<dfItem> df()
{
List<dfItem> dfItems = new List<dfItem>();
WebReference.Application app = new WebReference.Application();
var result = app.df(new WebReference.df()/*...*/);
foreach (var item in result.dfResult)
{
string[] info = item.Split(';');
dfItem dfItem = new dfItem()
{
MountPoint = info[0].ToString(),
Usage = info[1].ToString()
};
dfItems.Add(dfItem);
}
return dfItems;
}
//...
}
页面调用服务:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
LinuxServiceClient client = new LinuxServiceClient();
client.dfCompleted += new EventHandler<dfCompletedEventArgs>(client_dfCompleted);
client.dfAsync();
}
void client_dfCompleted(object sender, dfCompletedEventArgs e)
{
DG.ItemsSource = e.Result;
DG.Visibility = System.Windows.Visibility.Visible;
}
我的问题是当我导航到这个页面时,从ws(局域网中的ws)获取数据需要4-8秒。
我真的怀疑线路带宽可以创造这个等待时间......
我的问题: 您有什么建议可以加快速度吗?
系统信息:
UbuntuServer 11.04
Python:Python 2.7
Soaplib:soaplib 2.0.0-beta2
Windows:Windows 7 sp1
Silverlight:Silverlight 4
【问题讨论】:
-
如果您告诉我们您正在使用哪些 Python 和 soaplib 版本会有所帮助,因为这不是有效的 2.7/0.8.1。编写一个简单的 Python 肥皂客户端来查看是 Silverlight 还是导致延迟的 Python 也会很有用(我怀疑 Silverlight(因为我总是怀疑 Silverlight))。
-
添加了有关 python 的信息,...我会尝试编写一个简单的 Python 肥皂客户端..
-
我测试了 ws 就像在 helloworld 示例中一样...首先运行缓慢,然后运行快速...有什么想法吗?
标签: python windows linux web-services silverlight-4.0