Web Services on Rails

Here are some code examples:

I had difficulty consuming a webservice from a currently running server. ( maybe edit concurrent connections might fix this )

Make the site” test” and code it up.

Copy the site to "test2" 

cd test1
script/server --port=3000

cd test2
script/server --port=3001

open http://localhost:3001/ws

Publishing soap webservices from rails

File app:apis:subscription_api

class SubscriptionApi < ActionWebService::API::Base
  api_method :subscribe,:expects=>[:string],:returns=>[:string]
end

File app:controllers:subscription_controller

class SubscriptionController < ApplicationController wsdlservicename ‘subscription’

def subscribe(blib) return “You sent: ” + blib end end

Consuming soap webservices from rails

Here are 3 examples of consuming web services. make a controller called ws The wsdl and api are automaticly generated for you by rails at runtime

require 'soap/wsdlDriver'
class WsController < ApplicationController
    def index
        factory = SOAP::WSDLDriverFactory.new("http://localhost:3000/subscription/wsdl")
        service = factory.create_rpc_driver
        render :text => service.subscribe("hey there")
    end
end

# no require needed
class WsController < ApplicationController
    web_client_api :subscription, :soap, "http://localhost:3000/subscription/api" 
    def index
        render :text => subscription.subscribe("in")
    end
end


# no require needed
class WsController < ApplicationController
    def index
        subscription = ActionWebService::Client::Soap.new(SubscriptionApi,"http://localhost:3000/subscription/api")
        render :text => subscription.subscribe("in")
    end
end

Consuming soap webservices from ruby.

require 'soap/wsdlDriver'
factory = SOAP::WSDLDriverFactory.new("http://localhost:3000/subscription/wsdl")
service = factory.create_rpc_driver
p service.subscribe("hey there")

This entry was posted on Fri, 27 Oct 2006 11:25:37 GMT and Posted in . You can follow any any response to this entry through the Atom feed. You can leave a comment .


Comments

Leave a response

Leave a comment