Forum: Ruby on Rails Failed. Response code = 404 error. ActiveResource, RoR, REST

Posted by Jo (Guest)
on 2012-07-16 10:40
(Received via mailing list)
Hi all,
I try to create a RoR app to consume a RESTFul WCF service.

I used WebInvoke to wrap WCF service then launched it by using Visual 
studio
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;

namespace WCF_REST
{
    [ServiceContract]
    public interface IRestServiceImpl
    {
        [OperationContract]
        [WebInvoke(Method = "GET", ResponseFormat = 
WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "{id}")]
        string XMLData(string id);

        [OperationContract]
        [WebInvoke(Method = "GET", ResponseFormat = 
WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "json/{id}")]
        string JSONData(string id);
    }
}

So type http://localhost:50173/RestServiceImpl.svc/json/19... 
in
the browser, it will return a json file on screen.

Then I created a RoR app trying to consumer this WCF service
the controller class:
require 'active_resource'
class ServiceController < ApplicationController
  def show
    @wcf_service = RestServiceImpl.find(1)
  end
end
class RestServiceImpl < ActiveResource::Base
  self.site = "http://localhost:50173/"
end

View:
<h1>Hello Ruby!</h1>
<p>
  <%= @wcf_service %>
</p>

Then I launched the RoR app on rubymine built in server WEBrick, and 
type
this URL: http://127.0.0.1:3000/show
then I got
ActiveResource::ResourceNotFound in ServiceController#show

Failed.  Response code = 404.  Response message = Not Found


Any idea? I do not have a deep understanding about using the RoR,
activeresource and REST, so any help will do.
Many thanks.
Posted by Hassan Schroeder (Guest)
on 2012-07-16 20:23
(Received via mailing list)
On Thu, Jul 12, 2012 at 7:34 AM, Jo <jianping.zhou.1986@gmail.com> 
wrote:
> I try to create a RoR app to consume a RESTFul WCF service.

> So type http://localhost:50173/RestServiceImpl.svc/json/19... in
> the browser, it will return a json file on screen.

> then I got

> Failed.  Response code = 404.  Response message = Not Found

404 is pretty plain; the URL your app is requesting isn't what your
web service is responding to. Look at how they're different.

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Posted by Matt Jones (Guest)
on 2012-07-17 14:38
(Received via mailing list)
On Thursday, 12 July 2012 10:34:57 UTC-4, Jo wrote:
> using System.ServiceModel;
> BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "{id}")]
> the browser, it will return a json file on screen.
>

You're getting a 404 because ActiveResource doesn't know how to 
formulate a
URL for your service - it's going to be trying:

 http://localhost:50173/rest_service_impls/1

which obviously won't work. You'll either need to figure out how to 
remap
that on the IIS side (surely there's an equivalent of mod_rewrite) or 
dig
into the ActiveResource docs to tell *it* how to create the correct 
URLs.

--Matt Jones
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.