Changing web service url in SUDS library

谁说胖子不能爱 提交于 2019-12-19 10:24:36

问题


Using SUDS SOAP client how do I specify web service URL. I can see clearly that WSDL path is specified in Client constructor but what if I wan't to change web service url?


回答1:


Suds supports WSDL with multiple services or multiple ports (or both), and without having any detailed information on what you're working with, I am only guessing that this is what you are looking for. This question would be easier to answer if you provided more detail, such as what your Client instance looks like.

After you have successfully constructed a Client, you can print it to see the available services, methods, ports, and types.

The following example is straight from the suds documentation.

Example from suds site:

from suds.client import Client
url = 'http://www.thomas-bayer.com/axis2/services/BLZService?wsdl'
client = Client(url) 
print client

Outputs this:

Suds - version: 0.3.7 build: (beta) R550-20090820

Service (BLZService) tns="http://thomas-bayer.com/blz/"
   Prefixes (1)
     ns0 = "http://thomas-bayer.com/blz/"
   Ports (2):
     (soap)
       Methods (1):
         getBank(xs:string blz, )
     (soap12)
       Methods (1):
         getBank(xs:string blz, )
   Types (5):
      getBankType
      getBankResponseType
      getBankType
      getBankResponseType
      detailsType

Service (OtherBLZService) tns="http://thomas-bayer.com/blz/"
   Prefixes (1)
     ns0 = "http://thomas-bayer.com/blz/"
   Ports (2):
     (soap)
       Methods (1):
         getBank(xs:string blz, )
     (soap12)
       Methods (1):
         getBank(xs:string blz, )
   Types (5):
      getBankType
      getBankResponseType
      getBankType
      getBankResponseType
      detailsType

Each service can be accessed in many ways, but here is a different port from each service qualified by method:

## service: BLZService, port: soap12, method: getBank
client.service['BLZService']['soap12'].getBank()
## service: OtherBLZService, port: soap, method: getBank
client.service['OtherBLZService']['soap'].getBank()

Is that the kind of thing you're working with? If so, visit their documentation, which I think you'll find more than adequate. If not, please consider adding as much detail as possible to your question to give us more to work with!




回答2:


You can point the client to different endpoints via two methods:

1) client.set_options(location='http://path/to/your/wsdl') -or- 2) using the client's clone() method. Then use set_options() again. It's really the same as #1 above but you end up with two clients to use, not one.

This latter method is a clean way to create a lightweight clone of your client object - they'll share the parsed wsdl and will only differ on their options, which you set via set_options().

I use both methods and they both work very well.

-Matt




回答3:


I think you have to create a new Client object for each different URL.



来源:https://stackoverflow.com/questions/1670569/changing-web-service-url-in-suds-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!