0

I have complex requstDto which composed of other list of DTO's (Entity framework Entities) like

[Route("/demoservice/{Userdemo}/{EmployerDemoid}/{ReportDemo}/{DemoselectedDataList}/", "POST")]
        public class ReportDemo : IReturn<String>
        {
           
            public List<selectedidList> selectedDataList{ get; set; }            
            
        } 

where UserReport is follows

public class UserReport  
        {
            public string UserName { get; set; }
            public Datetime CreatedON{ get; set; }                       
            
        } 

when i try to post to request it gives me following error

A potentially dangerous Request.Path value was detected from the client (:)

i think it gives error due to : in CreatedON field ( for time part).

is the post values are also sent through URL to ServiceStack URL ? if yes

1) what if we have very large and complex requestDTO resulting into large number of characters (greater than allowed )in URL?

2) how to make above scenario work as ":" is reserved and cant be sent through URL?

3) How to see request URL Generated from client ?

My Client code in MVC.net is

var client = new JsonServiceClient(ConfigurationManager.AppSettings["applicationUrl"])
                {
                    //for windows authentication
                    Credentials = CredentialCache.DefaultCredentials      

                };

 var result = client.Post (new ReportDemo 
                 {
                     UserName = model.UserName,
                     EmployerID = model.EmployerID,
                     Report = model.Report,
                     selectedDataList =userReportViewModel.selectedDataList 

                 });

Thanks in advance, Amol

A_m0
  • 974
  • 2
  • 17
  • 45

1 Answers1

2

Only the /path/info of the Url should be specified in the [Route]. Ideally routes should use a human-readable logically-structured Url that refers to a "Resource" (noun). See the SeviceStack REST Events Example for different examples.

Routes should also never include complex types and any variable that isn't on the [Route] is automatically sent in the HTTP Request Body for POST requests or the QueryString from GET Requests.

For a User Report like this I would choose a URL that identifies the report, if the report has a name like "Demo Report" I would use a path info like:

[Route("/reports/demo")] 
public class ReportDemo : IReturn<String> { ... }

Otherwise if this is a Report for Users you may instead want to use something like:

[Route("/users/{UserName}/reports/demo")] 
public class ReportDemo : IReturn<String> { ... }

You can check what url is used by using the Reverse Routing Extension methods, e.g:

var request = ReportDemo { UserName = "Foo", ... };

request.ToPostUrl().Print(); //= /users/Foo/reports/demo

Now you can send your Request with any property not in the Route getting POST'ed to the above url, e.g:

string result = client.Post (new ReportDemo {
     UserName = userReportViewModel.UserName,
     EmployerID = userReportViewModel.EmployerID,
     Report = userReportViewModel.Report,
     selectedDataList =userReportViewModel.selectedDataList 
 });

If your Report does return a string you can use IReturn<string> however if it returns a Response DTO you'll want to use that instead, e.g IReturn<ReportDemoResponse>.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390