2011-04-18 1 views
2

에서 슬래시없이이 :ASP.NET 라우팅 -으로 다음과 같은 서비스 계약을 고려 끝에

[WebGet(UriTemplate = "/stores")] 
DTO.Stores GetAllStores(); 

[WebGet(UriTemplate = "/stores/{name}")] 
DTO.Stores GetStores(string name); 

나는이 두 개의 URL에 도달 할 수 있습니다 : http://localhost/v1/storeshttp://localhost/v1/stores/Joe을. 그러나 URL http://localhost/v1/stores/ (끝 부분에 슬래시가 있음)은 "엔드 포인트를 찾을 수 없음"오류를 리턴합니다. 이상적으로는 http://localhost/v1/stores/에 GetAllStores()를 호출하고 싶습니다.

어떻게하면됩니까? 감사!

답변

0

물결표를 넣으려고합니다. 아마도 "~/stores"입니까?

또는 라우팅을 사용하여 앞면에 "/"를 놓습니다.

0

"문자열? 이름"을 매개 변수로 사용하면 어떨까요?

[WebGet(UriTemplate = "/stores/{name}")] 
DTO.Stores GetStores(string? name); 

그리고 두 방법 때문에 당신이 같은 일 (DTO.Stores) (당신이 지금하고있는대로) 대신 두의 상점을 얻을 수있는 하나의 방법을 사용할 수를 반환하는 한

. 이와 같이 :

[WebGet(UriTemplate = "/stores/{name}")] 
DTO.Stores GetStores(string? name) 
{ 
    if(string.IsNullOrEmpty(name)) 
    { 
     //get specific store 
    } 
    else 
    { 
     //get all stores 
    } 
} 

P .: 나는 그것이 WCF와 잘 작동하는지는 잘 모르겠지만 시도해보십시오. ;-)