我正在编写一个控制台应用程序,它使用wsdl提供的Read函数来提取smartserver数据点。通过suds,我可以成功连接到smartserver并打印客户端wsdl,它为我提供了方法和类型列表。如何通过suds来使用这些方法来提取数据?我已经尝试打印client.service.List(),根据这个服务器的程序员文档应该给我数据点,但这给了我一个urlopen错误[Errno 13]权限被拒绝。该手册提供了仅使用SOAP来提取数据的示例代码,但由于我使用suds很多这个代码都是简化的,我只需要做client.service.somemethod(参数)我已经附加了我的代码到目前为止我打印客户端时获得的方法列表。
非常感谢。
import suds
from suds.client import Client
from suds.transport.http import HttpAuthenticated
url = "http://example/WSDL/v4.0/foo.WSDL"
client = Client(url, username='foo', password='bar')
myheaders = dict(userid='foo', passwd='bar')
client.set_options(soapheaders=myheaders)
name = client.factory.create('ns0:E_xSelect')
print name
name['xSelect'] = """//Item[UCPTpointName = "Net/MB485/MAIN POWER/Fb/PowerSum"]"""
print client.service.Read(name)
Ports (1):
(iLON100httpPort)
Methods (8):
Clear(ns0:Item_Coll iLonItem, )
Delete(ns0:Item_Coll iLonItem, )
Get(ns0:Item_Coll iLonItem, )
InvokeCmd(ns0:Item_Coll iLonItem, )
List(ns0:E_xSelect iLonItem, )
Read(ns0:Item_Coll iLonItem, )
Set(ns0:Item_CfgColl iLonItem, )
Write(ns0:Item_DataColl iLonItem, )
static void Main(string[] args)
{
iLON_SoapCalls.BindClientToSmartServer(); iLON_SmartServer.iLON100portTypeClient SmartServer = iLON_SoapCalls._iLON;
// -------------- READING A DATA POINT VALUE --------------
try
{
// instantiate the member object
iLON_SmartServer.Item_Coll itemColl = new iLON_SmartServer.Item_Coll(); itemColl.Item = new iLON_SmartServer.Item[1];
itemColl.Item[0] = new iLON_SmartServer.Dp_Data();
// set the DP name
itemColl.Item[0].UCPTname = "Net/LON/iLON App/Digital Output 1/nviClaValue_1";
// set maxAge to get the updated DP value in case it has been cached for more than 10 // seconds on the Data Server (see section 4.3.4.1 for more information) ((iLON_SmartServer.Dp_Data)(itemColl.Item[0])).UCPTmaxAge = 10; ((iLON_SmartServer.Dp_Data)(itemColl.Item[0])).UCPTmaxAgeSpecified = true;
//call the Read Function
iLON_SmartServer.Item_DataColl dataColl = SmartServer.Read(itemColl);
if (dataColl.Item == null)
{
// sanity check. this should not happen
Console.Out.WriteLine("No items were returned");
}
else if (dataColl.Item[0].fault != null)
{
// error
Console.Out.WriteLine("An error occurred. Fault code = " +
dataColl.Item[0].fault.faultcode +
". Fault text = %s." +
dataColl.Item[0].fault.faultstring);
}
else
{
// success
Console.Out.WriteLine("Read is successful");
Console.Out.WriteLine(((iLON_SmartServer.Dp_Data)dataColl.Item[0]).UCPTname + " = " + ((iLON_SmartServer.Dp_Data)dataColl.Item[0]).UCPTvalue[0].Value + "\n");
}
答案 0 :(得分:0)
我弄明白了这个问题。您必须以xml格式打开通过soap访问的wsdl,并阅读指定位置的名为wsdl services的部分。在客户端构造函数中定义该位置以成功与服务器通信。由于某种原因,suds没有在wsdl文件中看到这个位置。