调用Service的Python代码.C#中的等效代码是什么

本文关键字:代码 是什么 Python 调用 Service | 更新日期: 2023-09-27 18:27:47

我在Python中得到了一些代码来调用SOAP web服务。我想用C#编写等效的代码。我是Python的新手,所以在c#中找不到等价的类。我尝试过创建代理和其他方式,但没有成功。请帮忙。

import suds
from suds.client import Client
from suds.wsse import *
def main():
    url = 'https://webservices.cp.com/webservices/cphargepoint/services/4.1'
    wsdl = 'https://webservices.cp.com/api.wsdl'
    # API user and password
    api_user = 'yrewte44'
    api_pass = 'eg430'
    # create client and add security tokens in the soap header
    client = Client(url=wsdl, location=url)
    security = Security()
    token = UsernameToken(api_user, api_pass)
    security.tokens.append(token)
    client.set_options(wsse=security)
    try:
        # un-comment the print statement below to see the list of all published
        # CP service SOAP methods.
        # print client
        # getPublicStations() service method accepts a type of 'stationSearchRequest'
        searchQuery = client.factory.create('stationSearchRequest')
        # add properties/filter options
        searchQuery.Proximity = 10
        searchQuery.proximityUnit = 'M'
        # create goeData, provide starting point co-ordinates
        geoData = client.factory.create('geoData')
        geoData.Lat = 37.425758
        geoData.Long = -122.097807
        searchQuery.Geo = geoData
        # here is the actual call to the service        
        response = client.service.getPublicStations(searchQuery)
        # do whatever with the data
        # print response
    except suds.WebFault as detail:
        print detail
if __name__=="__main__":
    main()

调用Service的Python代码.C#中的等效代码是什么

您可以通过Visual Studio轻松地添加web服务(soap)作为对C#项目的引用。下面有一篇关于这方面的好文章:http://a1ashiish-csharp.blogspot.com/2012/01/cnet-how-to-consume-web-service-in-cnet.html

完成此操作后,您可以使用添加的web服务的对象和方法。