2012-06-18 76 views
0

字符串我有非常简单的代码:获取REST调用没有返回,我把网址

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/test

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

键入当我使用http://www.example.com/api/calc/?type=test返回它返回这个:

<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

两两件事,我没有一个默认的,在这里添加此之后:'公共静态无效的RegisterRoutes(RouteCollection路线) { routes.MapHttpRoute(名称:“路径1”,routeTemplate:“API /计算器/ {type}“,默认值:new {controller =”Calc“} ); }' – wizage

+0

添加此路由后它工作吗? – VJAI

+0

不,它不工作它仍然返回此:'' – wizage