Hello fellow Railers, I''ve written a WebserviceHelper which I thought some folks may find useful. What does it do? ============ Provides an easy way to drop in SOAP-based web services into your controllers. It can generate typed WSDL for you, which means people using .NET can use your web service and they''ll still get their nice "int", "bool", "CustomStruct" types in their C#-side API. How does it work? ============= Its pretty non-intrusive. Declare that you are using the helper in your controller, and indicate which actions are going to serve as "entry points" (ports in WSDL terminology) to your API. Example: class ApiController < ApplicationController helper :webservice wsdl_port :person, PersonApi.new end What this does is generate the :person action, installing a filter object to dispatch SOAP actions when /api/person is accessed by clients. It also creates "wsdl" action accessible via /api/wsdl, which will output a WSDL file for the API. To get the typing right, you need to annotate attributes and methods in your PersonApi class to indicate the desired types for method input parameters and return values. Example: class PersonApi extend WebService wsdl def some_method_with_no_parameters_or_interesting_return_values end wsdl :out => [[Integer]] def method_returning_int_array [1, 2, 3] end wsdl :in => [String] def method_expecting_string(str) end end See http://blog.xeraph.org/software/WebserviceHelper/doc/ for more details on how it hangs together. Where do I get it? ============= http://blog.xeraph.org/software/WebserviceHelper/WebserviceHelper-0.1.tar.gz. Just extract over your Rails app, contains app/helper/webservice_helper.rb and lib/web/service.rb. The bulk of the code lies in lib/web/service.rb, and the vast majority of code in there is just to do with mapping between SOAP, WSDL and Ruby types. Someone more knowledgeable in this area, feel free to criticize the implementation, as I''m sure mine sucks :) I don''t believe you about .NET interoperability, how do I test that? ================================================= Have Mono or .NET framework installed (I''ve only testetd on Mono though). Do: $ wget http://localhost:3000/controller/wsdl $ mv wsdl Something.wsdl $ wsdl -o Something Something.wsdl $ vi SomethingService.cs ... add a Main() that calls methods on a SomethingService instance ... $ mcs -reference:System.Web.Services SomethingService.cs $ mono SomethingService.exe Comments, bug reports, suggestions welcome! Leon
This is awesome! Lets talk in IRC, i''m sure we can generalize this further so that XMLRpc can be supported with the same domain keywords. ActiveService anyone? On Sun, 30 Jan 2005 20:54:22 +1300, leon breedt <bitserf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello fellow Railers, > > I''ve written a WebserviceHelper which I thought some folks may find useful. > > What does it do? > ============> > Provides an easy way to drop in SOAP-based web services into your > controllers. It can generate typed WSDL for you, which means people > using .NET can use your web service and they''ll still get their nice > "int", "bool", "CustomStruct" types in their C#-side API. > > How does it work? > =============> > Its pretty non-intrusive. Declare that you are using the helper in > your controller, and indicate which actions are going to serve as > "entry points" (ports in WSDL terminology) to your API. > > Example: > > class ApiController < ApplicationController > helper :webservice > > wsdl_port :person, PersonApi.new > end > > What this does is generate the :person action, installing a filter > object to dispatch SOAP actions when /api/person is accessed by > clients. It also creates "wsdl" action accessible via /api/wsdl, which > will output a WSDL file for the API. > > To get the typing right, you need to annotate attributes and methods > in your PersonApi class to indicate the desired types for method input > parameters and return values. > > Example: > > class PersonApi > extend WebService > > wsdl > def some_method_with_no_parameters_or_interesting_return_values > end > > wsdl :out => [[Integer]] > def method_returning_int_array > [1, 2, 3] > end > > wsdl :in => [String] > def method_expecting_string(str) > end > end > > See http://blog.xeraph.org/software/WebserviceHelper/doc/ for more > details on how it hangs together. > > Where do I get it? > =============> > http://blog.xeraph.org/software/WebserviceHelper/WebserviceHelper-0.1.tar.gz. > > Just extract over your Rails app, contains > app/helper/webservice_helper.rb and lib/web/service.rb. > > The bulk of the code lies in lib/web/service.rb, and the vast majority > of code in there is just to do with mapping between SOAP, WSDL and > Ruby types. Someone more knowledgeable in this area, feel free to > criticize the implementation, as I''m sure mine sucks :) > > I don''t believe you about .NET interoperability, how do I test that? > =================================================> > Have Mono or .NET framework installed (I''ve only testetd on Mono though). > > Do: > > $ wget http://localhost:3000/controller/wsdl > $ mv wsdl Something.wsdl > $ wsdl -o Something Something.wsdl > $ vi SomethingService.cs > ... add a Main() that calls methods on a SomethingService instance ... > $ mcs -reference:System.Web.Services SomethingService.cs > $ mono SomethingService.exe > > Comments, bug reports, suggestions welcome! > Leon > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Tobi http://www.hieraki.org - Open source book authoring http://blog.leetsoft.com - Technical weblog
Very cool stuff. I will probably use this to add SOAP support for http://soapbx.com Pelle On Sun, 30 Jan 2005 20:54:22 +1300, leon breedt <bitserf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello fellow Railers, > > I''ve written a WebserviceHelper which I thought some folks may find useful. > > What does it do? > ============> > Provides an easy way to drop in SOAP-based web services into your > controllers. It can generate typed WSDL for you, which means people > using .NET can use your web service and they''ll still get their nice > "int", "bool", "CustomStruct" types in their C#-side API. > > How does it work? > =============> > Its pretty non-intrusive. Declare that you are using the helper in > your controller, and indicate which actions are going to serve as > "entry points" (ports in WSDL terminology) to your API. > > Example: > > class ApiController < ApplicationController > helper :webservice > > wsdl_port :person, PersonApi.new > end > > What this does is generate the :person action, installing a filter > object to dispatch SOAP actions when /api/person is accessed by > clients. It also creates "wsdl" action accessible via /api/wsdl, which > will output a WSDL file for the API. > > To get the typing right, you need to annotate attributes and methods > in your PersonApi class to indicate the desired types for method input > parameters and return values. > > Example: > > class PersonApi > extend WebService > > wsdl > def some_method_with_no_parameters_or_interesting_return_values > end > > wsdl :out => [[Integer]] > def method_returning_int_array > [1, 2, 3] > end > > wsdl :in => [String] > def method_expecting_string(str) > end > end > > See http://blog.xeraph.org/software/WebserviceHelper/doc/ for more > details on how it hangs together. > > Where do I get it? > =============> > http://blog.xeraph.org/software/WebserviceHelper/WebserviceHelper-0.1.tar.gz. > > Just extract over your Rails app, contains > app/helper/webservice_helper.rb and lib/web/service.rb. > > The bulk of the code lies in lib/web/service.rb, and the vast majority > of code in there is just to do with mapping between SOAP, WSDL and > Ruby types. Someone more knowledgeable in this area, feel free to > criticize the implementation, as I''m sure mine sucks :) > > I don''t believe you about .NET interoperability, how do I test that? > =================================================> > Have Mono or .NET framework installed (I''ve only testetd on Mono though). > > Do: > > $ wget http://localhost:3000/controller/wsdl > $ mv wsdl Something.wsdl > $ wsdl -o Something Something.wsdl > $ vi SomethingService.cs > ... add a Main() that calls methods on a SomethingService instance ... > $ mcs -reference:System.Web.Services SomethingService.cs > $ mono SomethingService.exe > > Comments, bug reports, suggestions welcome! > Leon > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- http://talk.org + Live and direct from Panama http://SoapBX.com + Get on the box and shout http://econotrix.com + Rants on the economy and everything http://neuclear.com + The World Wide Web of Assets
On Mon, 31 Jan 2005 13:34:06 +0100, Pelle Braendgaard <pelleb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Very cool stuff. I will probably use this to add SOAP support for > http://soapbx.comHi, Just a FYI, At the suggestion of Tobias Luetke, I''m going to be generalizing this somewhat, in the hope that it will be useful for Rails itself (I didn''t know web services was one of the 1.0 goals). This probably means your API object is going to derive from something like ActionService::Base instead of extending WebService. Also, you''re going to be able to defer creation of the API object until much later: class ApiController < ApplicationController interface :person { PersonApi.new(@something) } end The block you pass will be instance_evaled in the controller itself, so it will have access to any variables set up by your filters, for example. Also, XML-RPC support is coming. XML-RPC will most likely work without any additional requirements. I.e. the URL the SOAP messages are POSTed to will be the same as the one that XML-RPC methods are POSTed to, as I can look for SOAPAction HTTP headers to figure out which is which. Those are the major changes I see happening. But what you have now should tide you over until then... Leon
I don''t know if anyone else finds this sort of thing useful. But I''ve been using the following snippet for building REST web services with rails: module ActionController class AbstractRequest def post_xml REXML::Document.new(self.raw_post) end end end On Tue, 1 Feb 2005 16:47:09 +1300, leon breedt <bitserf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mon, 31 Jan 2005 13:34:06 +0100, Pelle Braendgaard <pelleb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Very cool stuff. I will probably use this to add SOAP support for > > http://soapbx.com > Hi, > > Just a FYI, > > At the suggestion of Tobias Luetke, I''m going to be generalizing this > somewhat, in the hope that it will be useful for Rails itself (I > didn''t know web services was one of the 1.0 goals). > > This probably means your API object is going to derive from something > like ActionService::Base instead of extending WebService. > > Also, you''re going to be able to defer creation of the API object > until much later: > > class ApiController < ApplicationController > interface :person { PersonApi.new(@something) } > end > > The block you pass will be instance_evaled in the controller itself, > so it will have access to any variables set up by your filters, for > example. > > Also, XML-RPC support is coming. XML-RPC will most likely work without > any additional requirements. I.e. the URL the SOAP messages are POSTed > to will be the same as the one that XML-RPC methods are POSTed to, as > I can look for SOAPAction HTTP headers to figure out which is which. > > Those are the major changes I see happening. But what you have now > should tide you over until then... > > Leon > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz