0
votes

Why am I getting this error msg? {"Message":"No HTTP resource was found that matches the request URI 'http://www.test.com:7043/API/RunningValue_Import'.","MessageDetail":"No action was found on the controller 'RunningValue_Import' that matches the request."}

Here is the code:

public class RunningValue_ImportController : ApiController
{
    string temp001 = ""; //breakpoint here but it wont enter into the function below

    // POST api/RunningValue_Import
    public object PostRunningValue_Import(string xml)
    {
        string temp = String.Empty;
        try
        {
            temp = xml;
        }
        catch (Exception ee)
        {
            return new { isError = true, Msg = ee.ToString() };
        }
        return new { isError = false, Msg = "successful." };
    }
}

Fiddler:

POST http: //www.test.com:7043/API/RunningValue_Import HTTP/1.1
Accept: */*
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.test.com:7043/Html/cURL.html
Accept-Language: en-US
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0; ATT)
Host: www.test.com:7043
Content-Length: 12
DNT: 1
Connection: Keep-Alive
Pragma: no-cache

xml=WhateverStringGoesHere

Any ideas? Thanks

2

2 Answers

0
votes

If you are using the default routing, then the request for URI = http://www.test.com:7043/API/RunningValue_Import will look for an Index() action method. Since your action method is named PostRunningValue_Import, it's not matching any route defined in the Routes Dictionary.

If you want, you can try giving it the ActionName as follows.

// POST api/RunningValue_Import    
[ActionName("Index")]
public object PostRunningValue_Import(string xml)
{

If you were curious, here's some interesting info on how a Method becomes an Action. http://haacked.com/archive/2008/08/29/how-a-method-becomes-an-action.aspx/

0
votes

Change your action signature to public object PostRunningValue_Import([FromBody]string xml) as by default string type is expected to come from Uri.