Java python的服务端点接口
我正在研究java,eclipse提供了一些工具,比如wsimport,它通过向工具指定web服务的URL来导入所有java文件和类文件。python有类似的东西吗?我们如何使用python来使用任何web服务。python应该有一些服务端点接口,对吗?如果有,我们如何使用它?请帮忙,提前谢谢 将完成这项工作。它易于使用,并且公开了web服务的方法和对象类型 例如:Java python的服务端点接口,java,web-services,python-3.x,service,endpoint,Java,Web Services,Python 3.x,Service,Endpoint,我正在研究java,eclipse提供了一些工具,比如wsimport,它通过向工具指定web服务的URL来导入所有java文件和类文件。python有类似的东西吗?我们如何使用python来使用任何web服务。python应该有一些服务端点接口,对吗?如果有,我们如何使用它?请帮忙,提前谢谢 将完成这项工作。它易于使用,并且公开了web服务的方法和对象类型 例如: >>> import suds >>> from suds.client import Cli
>>> import suds
>>> from suds.client import Client
>>> client = Client('http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL')
>>> print(client)
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):
ArrayOfForecast
ArrayOfWeatherDescription
Forecast
ForecastReturn
POP
WeatherDescription
WeatherReturn
temp
...
如您所见,客户机
类只需要一个URL就可以打印出web服务的信息
>>> weather = client.service.GetCityWeatherByZIP('02118')
>>> print(weather)
(WeatherReturn){
Success = True
ResponseText = "City Found"
State = "MA"
City = "Boston"
WeatherStationCity = "Boston"
WeatherID = 14
Description = "Cloudy"
Temperature = "64"
RelativeHumidity = "80"
Wind = "S9"
Pressure = "30.19F"
Visibility = None
WindChill = None
Remarks = None
}
client
对象有一个service
属性,允许您运行方法。当我运行GetCityWeatherByZIP
时,suds
将XML响应转换为Python对象(在本例中是WeatherReturn
对象)。您可以像访问任何其他Python对象一样访问其属性
>>> weather.Description
Cloudy
>>> weather.Wind
S9
您还可以使用Client.factory
创建自己的XML关联对象
>>> forecast = client.factory.create('Forecast')
>>> forecast.WeatherID = 6
>>> print(forecast)
(Forecast){
Date = None
WeatherID = 6
Desciption = None
Temperatures =
(temp){
MorningLow = None
DaytimeHigh = None
}
ProbabilityOfPrecipiation =
(POP){
Nighttime = None
Daytime = None
}
}
虽然有点过时,但应该可以帮助你开始