2012-06-18 3 views
0

에 넣어 문자열을 반환하지 않습니다 받기 :내가 아주 간단한 코드가 REST 호출 내가 URL을

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Net.Http; 
using System.Web.Http; 

namespace Calculator.Controllers 
{ 
    public class CalcController : ApiController 
    { 

     public string Get(string type) 
     { 

      return type; 
     } 

    } 
} 

을 그리고 이것은 내가 http://www.example.com/api/calc/?type=test을 사용하면 내가 http://www.example.com/api/calc/test

<string xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2003/10/Serialization/" i:nil="true"/> 

에 입력 할 때 반환 것입니다 그러면 다음과 같이 반환됩니다 :

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">test</string> 

내가 어떻게하면 맨 아래 하나가 될 수 있을까요?

답변

0

경로를 기본값 인 Global.asax.cs에 만들어야합니다.

routes.MapHttpRoute(
    name: "route1", 
    routeTemplate: "api/calc/{type}", 
    defaults: new { controller = "Calc" } 
); 
+0

두 가지 I는 기본 하나를 가지고하지 않으며 여기를 추가 한 후'공공 정적 무효 RegisterRoutes (RouteCollection 경로) { routes.MapHttpRoute (이름 : "route1", routeTemplate : "API/석회질을/{type} ", 기본값 : new {controller ="Calc "} ); }' – wizage

+0

이 경로를 추가 한 후에 작동합니까? – VJAI

+0

아니요 작동하지 않습니다. 여전히 다음과 같이 반환됩니다 :'' – wizage

관련 문제