【问题标题】:using suds to pull data points through wsdl on Smartserver 2.0在 Smartserver 2.0 上使用 suds 通过 wsdl 提取数据点
【发布时间】:2014-02-21 23:08:10
【问题描述】:

我正在编写一个控制台应用程序,该应用程序使用 wsdl 提供的读取功能提取智能服务器数据点。通过 suds,我可以成功连接到 smartserver 并打印客户端 wsdl,它为我提供了方法和类型的列表。如何通过 suds 使用这些方法来提取数据?我试过打印 client.service.List() 根据这个服务器的程序员文档应该给我数据点,但这给了我一个 urlopen 错误 [Errno 13] 权限被拒绝。该手册提供了仅使用 SOAP 来提取数据的示例代码,但由于我使用的是 suds,因此很多代码都被简化了,我只需要执行 client.service.somemethod(parameter) 到目前为止我已经附上了我的代码和列表我打印客户端时得到的方法。

非常感谢。

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");
    }

【问题讨论】:

    标签: python soap wsdl suds


    【解决方案1】:

    我发现了问题所在。您必须以xml 格式打开您通过soap 访问的wsdl,并阅读指定位置的名为wsdl services 的部分。在客户端构造函数中定义该位置以成功与服务器通信。由于某种原因,suds 在 wsdl 文件中没有看到这个位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-13
      • 2010-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-05
      相关资源
      最近更新 更多