簡體   English   中英

ServiceStack - 繼承 Single Restservice 中的所有 DTO 資源

[英]ServiceStack - inheriting all DTO resource in Single Restservice

如何在一項服務中繼承所有 DTO 資源?

比如說,

我有資源 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; } 
} 

我有我的服務 Class: 1.如何在此服務中繼承另一個 DTO Class?????????? 2.我需要為此創建單獨的 class 嗎??????

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

請就這個問題給我建議......

您可以在同一 web 服務中的同一資源(又名請求)DTO 上實現多個 HTTP 動詞,例如:

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

這允許您為以下 HTTP 操作提供多種實現:

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

雖然如果你使用 SOAP 你被限制為每個 web 服務的 1 個 RPC 方法,因為 SOAP 僅支持 Z2993C5EC9705EB7AC2C984033E06189DZ 服務。

最好的方法是從Service繼承並實現Any()方法,無論使用哪個 HTTP 動詞或端點來調用服務,都會調用該方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM