简体   繁体   中英

ServiceStack - inheriting all DTO resource in Single Restservice

How to inherit all DTO resource in one service?.

Say for example,

I Have Resource Class:

[RestService("/getstudentname", "GET,POST,PUT,OPTIONS")] 
public class RestResourcename 
{ 
public string Name { get; set; } 
}

[RestService("/getstudentID", "GET,POST,PUT,OPTIONS")] 
public class CNextRestResourceid 
{ 
 public string Name { get; set; } 
} 

I have my Service Class: 1.How to inherit another DTO Class in this Service???????? 2.Do i need to create seperate class for this?????

public class CnextRestService : RestServiceBase<RestResourcename> 
{ 
 public override object OnGet(RestResourcename request) 
 { 
    return request; 
 } 
} 

Please suggest me on this issues.......

You can implement multiple HTTP Verbs on the same Resource (aka Request) DTO in the same web service, eg:

public class CustomersService : Service
{
    object Get(GetCustomer request){...}
    object Post(CreateCustomer request){...}
    object Put(UpdateCustomer request){...}
    object Delete(DeleteCustomer request){...}
}

This allows you to provide multiple implementations for the following HTTP actions:

GET   /customers
GET   /customers/1
POST  /customers
PUT   /customers/1
DELETE /customers/1

Although if you use SOAP you're limited to 1 RPC method for each web service since SOAP only supports HTTP POST.

The best way to do this is to inherit from Service and implement the Any() method which will be called regardless of which HTTP Verb or endpoint was used to invoke the service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM