Access requesting IP from actionwebservice controller/model

I’m building a SOAP server for a rails project we have here.
I’m using actionwebservice to achieve this.

Inside the logic for one of the SOAP methods I need to read
the IP address of the requesting client.

For a regular rails controller we’ve been using this
construct, which works nicely

tmp_ip = request.env[“HTTP_X_FORWARDED_FOR”]
if(tmp_ip =~ /(\d+.\d+.\d+.\d+)$/)
tmp_ip = $1;
else
tmp_ip = request.remote_ip
end

But if I put that in either my webservice method or my webservice
controller I just get this error: “undefined local variable or
method `request’ for PsipredApiController:Class”

Here’s the controller:

class PsipredApiController < ApplicationController
web_service_dispatching_mode :delegated

@tmp_ip = request.env[“HTTP_X_FORWARDED_FOR”]
if(@tmp_ip =~ /(\d+.\d+.\d+.\d+)$/)
@tmp_ip = $1;
else
@tmp_ip = request.remote_ip
end

web_service :api_disopred, ApiDisopredService.new
web_service_scaffold :invoke
end

Here’s the API defs

class ApiDisopred < ActionWebService::API::Base

api_method :submit, :expects => [{:sequence=>:string},
{:email=>:string},{:name=>:string}, {:fpr => :string}, {:psiblast =>
:string},
{:psipred => :string}], :returns => [SubmitMessage]

api_method :results, :expects => [{:job_id=>:string}], :returns =>
[:string]

end

and here’s the methods

class ApiDisopredService < ActionWebService::Base
web_service_api ApiDisopred

def submit(sequence, email, name, fpr, psiblast, psipred)
[A GREAT DEAL OF LOGIC THAT WORKS]
results = SubmitMessage.new
results.message = @message
results.job_id = @job.id
results.state = @state
return results
end

end