python suds或sf-suds如何使用" wsdl:import"?

时间:2014-09-26 12:22:35

标签: python soap wsdl

例如,我在wsdl_url中有wsdl:

<wsdl:definitions ...>
   <wsdl:import namespace="wsdl/auth/v1/" location="wsdl/auth/v1/soap/auth.wsdl"/>
   <wsdl:import namespace="wsdl/core/v1/" location="wsdl/v1/soap/core.wsdl"/>
   ...
</wsdl>

如何从namespace="wsdl/auth/v1/"调用方法? auth.wsdl包含方法登录。

import suds
client = suds.client.Client(wsdl_url)
client.service.login(...)

1 个答案:

答案 0 :(得分:1)

我找不到具有两个命名空间的服务来测试,但逻辑似乎适用于此。

创建客户端后,将其打印出来。您将拥有以下内容:

url = "http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl"
client = suds.client.Client(url)
print client

Suds ( https://fedorahosted.org/suds/ )  version: 0.4 GA  build: R699-20100913

Service ( Weather ) tns="http://ws.cdyne.com/WeatherWS/"
   Prefixes (1)
      ns0 = "http://ws.cdyne.com/WeatherWS/"
   Ports (2):
      (WeatherSoap)
         Methods (3):
            GetCityForecastByZIP(xs:string ZIP, )
            GetCityWeatherByZIP(xs:string ZIP, )
            GetWeatherInformation()
         Types (8):
            ....
      (WeatherSoap12)
         Methods (3):
            GetCityForecastByZIP(xs:string ZIP, )
            GetCityWeatherByZIP(xs:string ZIP, )
            GetWeatherInformation()
         Types (8):
            ....

然后,您可以使用client.set_options(service='service1', port='port1')设置所需的服务。之后,只需调用service.function。 在示例中:

client.set_options(port='WeatherSoap12')
client.service.GetWeatherInformation()

更多信息:https://fedorahosted.org/suds/wiki/Documentation