unwire / handsoap

Handsoap is a library for creating SOAP clients in Ruby
http://github.com/unwire/handsoap
225 stars 58 forks source link

Dynamic endpoint assignment #8

Closed braposo closed 14 years ago

braposo commented 15 years ago

Is there a way to dynamically assign an endpoint? I want to define the endpoint from a URI stored in the database.

Thanks!

jimmiw commented 15 years ago

Hello,

Endpoints are assigned at class level, but it is possible to get the functionality you are looking for.

If you have a service class called CustomerService, and it inherits from the Handsoap::Service class, then you have a method called endpoint availiable.

This means that you can set the endpoint dynamically:

fetch endpoint URI from the database

# ...
# Set the endpoint on the service.
CustomerService.endpoint(some_endpoint)
# use the service

All you need to remember is, that this is all done on the class level. So you cannot have two instances of the CustomerService running, with two different endpoints.

braposo commented 15 years ago

Well, that's not a perfect solution, but I'll make it work.

Thank you for the reply.

benissimo commented 8 years ago

The lack of dynamic endpoints is a show stopper for me. Setting them on the class level is no good, I don't want have to resort to dynamically generating classes to get around the fact that no instance-level endpoint is available. Granted, most users do have a fixed endpoint; so I recognize this isn't a problem for everyone. But for those of us whose endpoint is dynamic (customer may specify the server's hostname, etc.), managing it at the class-level is a design flaw.

troelskn commented 8 years ago

Not arguing with you on that @benissimo - If you want to provide a PR that makes it possible to assign endpoint on an instance level, I'd be happy to merge it.

benissimo commented 8 years ago

I tried forking the gem and running tests, but got bogged down with finding the right set of dependencies to run them. Would be great if you could add a Gemfile and/or list of development dependencies.

In the meantime, I realized that in my specific case, since all I really need is for the endpoint uri to be instance based, I can simply override Handsoap::Service#uri (the instance method) with something dynamic. I can plug in a dummy value for the endpoint's uri at the class level and let my override of #uri define its real, dynamically-calculated value.

I've had good experience using Handsoap in previous cases, so was happy to find a way to continue to use it even in an area where I needed to support dynamic endpoints.

troelskn commented 8 years ago

Good to hear. I realise the tests are in a pretty bad condition. This project hasn't been kept much up to date over the years. At least you found a solution to the specific problem and hopefully anyone else who googles for the issue will end up here.