# NoMethodError: undefined method \`add\_rpc\_operation' for nil:

**URL:** <https://www.ruby-forum.com/t/nomethoderror-undefined-method-add-rpc-operation-for-nil/182104>\
**Category:** Ruby\
**Created:** [January 22, 2010, 6:36pm UTC](https://www.ruby-forum.com/t/nomethoderror-undefined-method-add-rpc-operation-for-nil/182104 "2010-01-22T18:36:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![farfignugen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/f17d59/32.png) [@farfignugen](https://www.ruby-forum.com/u/farfignugen)\
**Post date:** [January 22, 2010, 6:36pm UTC](https://www.ruby-forum.com/t/nomethoderror-undefined-method-add-rpc-operation-for-nil/182104/1 "2010-01-22T18:36:23Z")

</div>

FYI: this is in a Sinatra app. Don’t know if that matters though.

NoMethodError: undefined method `add_rpc_operation' for nil:NilClass from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/soap/rpc/httpserver.rb:95:in`add\_rpc\_method\_as’  
from  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/soap/rpc/httpserver.rb:87:in  
`add_method' from ./soap_server/server.rb:8:in`initialize’  
from (irb):5:in `new’  
from (irb):5

I am running this in irb:

require ‘soap/rpc/standaloneServer’  
require ‘soap\_server/server’ # includes the SoapServer class  
server = SoapServer.new(‘hws’, ‘urn:hws’, ‘127.0.0.1’, 6565)

SoapServer class looks like this:

require File.dirname( **FILE** ) + ‘/…/vendor/gems/environment’  
require “soap/rpc/standaloneserver”

begin  
class SoapServer \< SOAP::RPC::StandaloneServer  
# Expose our services  
def initialize(\*args)  
add\_method(self, ‘add’, ‘a’, ‘b’)  
add\_method(self, ‘div’, ‘a’, ‘b’)  
end

```
# Handler methods
def add(a, b)
  return a + b
end
def div(a, b)
  return a / b
end

```

end  
rescue Exception =\> e  
puts e.message  
end

---

<div class="post-metadata">

**Author:** ![farfignugen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/f17d59/32.png) [@farfignugen](https://www.ruby-forum.com/u/farfignugen)\
**Post date:** [January 25, 2010, 5:54pm UTC](https://www.ruby-forum.com/t/nomethoderror-undefined-method-add-rpc-operation-for-nil/182104/2 "2010-01-25T17:54:23Z")

</div>

Ok I figured it out. Smallest change, but got it to work. Seems like  
super is creating an object that wasn’t being created that the  
initialize methods needs to run.

in the SoapServer class you need to add super before adding your  
methods. It should look like this.

class SoapServer \< SOAP::RPC::StandaloneServer

# Expose our services

def initialize(\*args)  
super  
add\_method(self, ‘add’, ‘a’, ‘b’)  
add\_method(self, ‘div’, ‘a’, ‘b’)  
end

# Handler methods

def add(a, b)  
return a + b  
end  
def div(a, b)  
return a / b  
end  
end
