This is a migrated thread and some comments may be shown as answers.

Response from REST Collections Service??

3 Answers 48 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dave
Top achievements
Rank 1
Dave asked on 09 May 2012, 01:23 PM
Hi All,

I am new to Telerik and I am currently trying to implement a Restful Web Service App that will accept Http injects and either display or process data. I have performed the following steps and I am having trouble:

  1. I have created a new Class Library project in visual studio.
  2. I then added a "Telerik OpenAccess Domain Model" to that project and successfully linked it to my database.
  3. I then Added a web project to my solution.
  4. I then used the Data Services Wizard (DWS) to create a REST Collections for the app, this was successful.
  5. From this a number of files were added to the project icluding ICollectionService.cs, DataManager.cs, Users.svc etc.

From here I then wanted to view the data in my database in xml or json. I setup some routing so that i could more easily access the service, as shown below:

Global asax.cs

using System;
using System.ServiceModel.Activation;
using System.Web;
using System.Web.Routing;
 
namespace WcfRestService1
{
    public class Global : HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes();
        }
 
        private void RegisterRoutes()
        {
            // Edit the base address of Users by replacing the "Users" string below
            RouteTable.Routes.Add(new ServiceRoute("Users", new WebServiceHostFactory(), typeof(Users)));
        }
    }
}


Once I then run the application and went to the routing address which should have pointed me to the Service I got an error saying is not compatible with asp.net, so I added the below code to the Users.svc.cs to fix it:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]



Now When I run the application and go to say the following address "http://localhost:14644/Users/", I get the results as shown below where as I would like it to show me the data in an XML/Json format.

 

Can anyone please help with this? If you need more info please let me know.

Thanks





3 Answers, 1 is accepted

Sort by
0
Dave
Top achievements
Rank 1
answered on 09 May 2012, 04:51 PM
I have managed to modify the data but now I am not sure exactly how I can create new Database entries using the REST Collections? I would like to create a new database entry using the value passed by a query string, can anyone help?

Thanks
0
Dave
Top achievements
Rank 1
answered on 11 May 2012, 12:45 PM
Hi,

So I have got a little further with this and by passing data to the Web Services I am able to do most things apart from Creating New Entries. I believe this is to do with the structure of the data I am sending to the service, can someone please help me with this?? I have included the data I am sending to the service below along with the error I get:

Header:
POST 
Accept: application/atom+xml
Content-Type: application/atom+xml;type=entry
Host: localhost:16485
Content-Length: 242

Data:
<User xmlns="http://schemas.datacontract.org/2004/07/SWF_Data_Access.DAL">
  <FACEBOOK_ID>999999999</FACEBOOK_ID>
  <Friends>
    <Friend>
      <FRIEND_ID>888888888</FRIEND_ID>
      <USER_ID>999999999</USER_ID>
     </Friend>
    </Friends>
</User>

Error: 
catch (OpenAccessException)
            {
                throw new Exception(Convert.ToString(HttpStatusCode.BadRequest));
            }

The error is thrown by the function above but it is not specific on what is the cause.

Thanks
0
Serge
Telerik team
answered on 13 May 2012, 05:08 PM
Hello Dave, 

 First of all I would like to point out that there is a new wizard that now handles the creation of services using OpenAccess. You will find it by right clicking on either an rlinq file or an web application in the solution explorer and selected "Generate OpenAccess Domain Service". 

As to the problems you are experiencing I will suggest attaching a debugger to the web project that is hosting the service and having a look at the actual exception. 

Another thing to consider is implement a WCF Data Service instead. They are quite easy to setup and also generated by our wizard. The Data Services are also REST oriented so this shouldn't be a problem. 

I hope this is helpful.
 
Greetings,
Serge
the Telerik team
Follow @OpenAccessORM Twitter channel to get first the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Tags
Development (API, general questions)
Asked by
Dave
Top achievements
Rank 1
Answers by
Dave
Top achievements
Rank 1
Serge
Telerik team
Share this question
or