# Consume .NET in rails

**URL:** <https://www.ruby-forum.com/t/consume-net-in-rails/140015>\
**Category:** Rails\
**Created:** [June 10, 2008, 4:13am UTC](https://www.ruby-forum.com/t/consume-net-in-rails/140015 "2008-06-10T04:13:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ADADAD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85e7bf/32.png) [@ADADAD](https://www.ruby-forum.com/u/ADADAD)\
**Post date:** [June 10, 2008, 4:13am UTC](https://www.ruby-forum.com/t/consume-net-in-rails/140015/1 "2008-06-10T04:13:07Z")

</div>

Hello,  
What is the preferred way to consume .NET webservices in rails?  
Currently  
we have a file in the lib directory handling all this but I would like a  
cleaner way to

1 - have the services act more “model” like so we can access data like  
NETApi.get\_users()

2 - Allow the rails client to login only once, as logging in each time  
for  
a request can be very slow on a very large wsdl file

Any suggestions? I am using soap4r now and it works fine but I think  
it  
can be tidier. Also logging in to the NET site on startup slows down  
launching future rails instances. Some sample below

module NETAPILibrary

require ‘soap/wsdlDriver’  
require ‘soap/header/simplehandler’  
require ‘uuid’

class AutheticationHeaderHandler \< SOAP::Header::SimpleHandler  
#The header is named “SecureHeader” in this web service.  
@@HEADER\_NAME = ‘AuthenticationHeader’  
def initialize(namespace, companyID, userID)  
super(XSD::QName.new(namespace, @@HEADER\_NAME))  
@user\_element = XSD::QName.new(namespace, ‘CompanyId’)  
@password\_element = XSD::QName.new(namespace, ‘UserId’)  
@companyID, @userID = companyID, userID  
end

```
 def on_simple_outbound
   {@user_element => @companyID, @password_element => @userID}
 end

```

end

def bt\_initialize  
$soap = SOAP::WSDLDriverFactory.new($BT\_WSDL\_URL).create\_rpc\_driver  
$soap.headerhandler \<\<  
AutheticationHeaderHandler.new(“[http://testapi.com/](http://testapi.com/)”,  
$bt\_rootid,$bt\_user\_id)  
end

def bt\_getmemberbyemail(email)  
res = $soap.GetMemberByEmail(:email =\> email)  
return res.getMemberByEmailResult.iD  
end
