无法调用REST函数

时间:2014-08-08 13:00:00

标签: c# json rest visual-studio-2013

我有一个WCF服务,我在我的web api MVC应用程序中使用这些功能。我遇到的错误是:

"No action was found on the controller that matches the request"

如果我早期的功能不起作用,问题就不会那么奇怪,但他们确实如此。 这是我的代码......

[ActionName("restfunctionname")]
public SortedList<string, PropertyClass> REST_Function([ModelBinder(typeof (CommaDelimitedArrayModelBinder))] string[] parameterList, string parameter2, string parameter3)
        {
            WCF wcfService = new WCF();

            List<string> arrayParameter = new List<string>();
            ids.AddRange(parameterList);

            SortedList<string, PropertyClass> returnValue = wcfService.GetTranslationsFromId(arrayParameter, paremeter2, parameter3);

            return returnValue;
        }

因此,返回值应为SortedList。

由于我在MVC中,在我的WebApiConfig中设置了这个:

config.Routes.MapHttpRoute(
                name: "restfunctionname",
                routeTemplate: "api/{controller}/{action}/{parameterList}/{parameter2}/{parameter3}",
                defaults: new { parameterList= RouteParameter.Optional, parameter2 = RouteParameter.Optional, parameter3 = RouteParameter.Optional }

            );

最后,我从浏览器调用我的函数试图在响应体中捕获JSON,如下所示:

http://localhost:20915/api/controller/restfunction/firstItemOfArray,SecondItemOfArray/parameter2/parameter3

......但没什么。我错过了什么吗?

感谢。

1 个答案:

答案 0 :(得分:1)

我的WCF函数中没有“GET”字样,例如......我的原始WCF函数名称为:TranslationFromID然后我将其更改为:GetTranslationFromID,现在它可以正常工作。

相关问题