Changing web service url in SUDS library
Asked Answered
S

3

2

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?

Snore answered 3/11, 2009 at 22:31 Comment(0)
A
4

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!

Achaemenid answered 21/1, 2010 at 4:10 Comment(3)
Actually what I was asking is how to modify endpoint (port) address on runtime. Your answer reminded me that this configuration can be in service description. And it was actually there. client.service['BLZService'].setlocation()Snore
Awesome, I'm really happy that I was able to help you. Congrats! :)Achaemenid
Using suds 0.4 this is client.wsdl.services[0].setlocation(new_url)Agitate
A
4

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

Ascent answered 23/1, 2010 at 13:36 Comment(0)
A
1

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

Amoeba answered 3/11, 2009 at 23:15 Comment(2)
But I'm passing WSDL url to Client constructor. What if WSDL and service have different URLs?Snore
The WSDL should contain all the details of the service URL. You just need one client object per wsdl and you shouldn't need to worry about the service url (as a client)Amoeba

© 2022 - 2024 — McMap. All rights reserved.