Change web service url for a suds client on runtime (keeping the wsdl)
Asked Answered
I

3

8

First of all, my question is similar to this one

But it's a little bit different. What we have is a series of environments, with the same set of services. For some environments (the local ones) we can get access to the wsdl, and thus generating the suds client. For external environment, we cannot access the wsdl. But being the same, I was hoping I can change just the URL without regenerating the client. I've tried cloning the client, but it doesn't work.


Edit: adding code:

    host='http://.../MyService.svc'
    wsdl_file = 'file://..../wsdl/MyService.wsdl'

    client = suds.client.Client(wsdl_file, location=host, cache=None)

    #client = baseclient.clone()

    #client.options.location = otherhost

    client.set_options(port='BasicHttpBinding_IMyService')

    result = client.service.IsHealthy()

That gives me this exception:

The message with Action 'http://tempuri.org/IMyService/IsHealthy' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

The thing is, if I set the client directly to the host, it works fine: client = suds.client.Client(host)

As you can see, I've tried cloning the client, but with the same exception. I even tried this:

    baseclient = suds.client.Client(host)

    client = baseclient.clone()

    client.options.location = otherhost
    ....

And got the same exception.

Anyone can help me?

Indignant answered 14/5, 2010 at 17:42 Comment(0)
M
6
client.sd[0].service.setlocation(new_url)

...is the "manual" way, ie. per service-description.

client.set_option(new_url)

...should also work, per the author.

options is a wrapped/protected attr -- direct edits may very well be ignored.

Martinson answered 13/2, 2013 at 20:53 Comment(1)
Some explanation or a link to documentation would make your answer a lot more valuable.Undecided
I
3

I've got it!. I don't even know how I've figured it out, but with a little of guessing and a much of luck I ended up with this:

    wsdl_file = 'file://...../MyService.wsdl'

    client = suds.client.Client(wsdl_file)
    client.wsdl.url = host #this line did the trick

    client.set_options(port='BasicHttpBinding_IMyService')

    result = client.service.IsHealthy()

And it works! I can't find any documentation about that property (client.wsdl.url), but it works, so I post it in case someone have the same problem.

Indignant answered 17/5, 2010 at 20:46 Comment(2)
argh! It was just getting the url from the file. The client.wsdl.url setting is modified, but it keep going to the original service.Indignant
So does it work? If not, perhaps a combination of client.wsdl.url and client.options.location? This is starting to feel hacky, perhaps the SUDS mailing list would be more helpful?Poss
P
1

You might be able to do that by specifying the location of the service. Assuming you have a Client object called client, you can modify the service location by updating the URL in client.options.location.

Additionally you are able to use a local copy of a WSDL file as the url when constructing the client by using a file:// scheme for the URL, e.g. file:///path/to/service.wsdl. So this could be another option for you. Of course you would also have to specify the location so that the default location from within the WSDL is overridden.

Poss answered 14/5, 2010 at 19:25 Comment(2)
I've tried a lot of things but I can't understand what I'm doing wrong. I'll add some code to the original question, It would be great if you could check itIndignant
My problem is that the service provider gives you a file. For test mode, you have to modify the wsdl file manually with the test url. I wanted to make the change dynamically after loading the file and updating the service address location. I don't think that is possible.Jenks

© 2022 - 2024 — McMap. All rights reserved.