Wednesday 11 April 2012

How to Fix Error "An error occurred while processing this request."

My try catch clause will produce the the following error
"An error occurred while processing this request."

I am trying to query WCF data service.

        DataServiceContext ctxError = new DataServiceContext(new Uri("http://localhost/WDS2/SchoolService.svc"));
        try
        {
            var dept = ctxError.Execute<ServiceReference1.Department>(new Uri("Departments", UriKind.RelativeOrAbsolute));
        }
        catch (Exception ecc)
        {
            Response.Write(ecc.Message);
        }

Problem is that both server and client are on the same machine.
To Fix:
 - not sure if this is the best solution, but when my server is using local web server client is using IIS - problem is fixed.
       DataServiceContext ctx = new DataServiceContext(new Uri("http://localhost:57080/WebSite1/SchoolService.svc"));
        var Orders = ctx.Execute<ServiceReference2.Department>(new Uri("Departments", UriKind.RelativeOrAbsolute));

        foreach (ServiceReference2.Department dpt in Orders)
        {
            Response.Write(dpt.Name);
            Response.Write("<br>");
        }

So here are my all steps.
1. Create new Empty Website
2. Ensure port number is not empty



3. Now add new item - ADO.NET Entity Data Model


4. Name it model

5. Say Yes to the warning above.

6. Click Next

 7. Save entity connection settings in Web.Config as SchoolEntities and click Next

8. I selected 2 tables - Department and Course - then Finish.

9. Add new item - WCF Data Service
10. Modify WcfDataService so
public class WcfDataService : DataService<SchoolModel.SchoolEntities>
and uncheck and modify the following
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);

11. Ensure that Port number is not empty

12. Whole code looks like in above picture.
12. Set WcfDataService.svc as startup page

13. Run project, you should get something similar to this:

14. Again, ensure there is some port number next to localhost.

15. Now create client - so for that purpose create new empty web site project
16. Add new web page to it.
17. Ensure it is using IIS

18. Add new item - WCF Data Service

19. Go to code in webpage  (will continue later)

No comments:

Post a Comment