2

I would like to add some web api to my project but I am getting error that No HTTP resource was found that matches the request URI

What I could miss in settings or how I can see all sitecore routs and test it ?

{"Message":"No HTTP resource was found that matches the request URI 'http://my.local/rrapi/My/GetSometing'.","MessageDetail":"No type was found that matches the controller named 'methodName'."}

It seems like I did all settings

MyController

[ServicesController]
    public class MyController : ServicesApiController
    {
        [HttpGet]
        public IHttpActionResult GetSometing(string code) 
        {            
            return Ok("Done");
        }
    }

RegisterWebApiRoutes

 public class RegisterWebApiRoutes
    {
        public void Process(PipelineArgs args)
        {
            RegisterRoutes(RouteTable.Routes, args);
        }

        private void RegisterRoutes(RouteCollection routes, PipelineArgs args)
        {
            if (routes["MyName.WebApi.Default"] != null)
            {
                Log.Warn("Route 'MyName.WebApi.Default' has already been added. Ensure only a single route processor for MyName WebApi.", this);

                return;
            }

            routes.MapHttpRoute("MyName.WebApi.Default", "rrapi/{controller}/{action}/{code}", new
                {
                    code = RouteParameter.Optional
                }
            //,
            //    new
            //    {
            //        httpMethod = new HttpMethodConstraint("Get", "Post", "Delete")
            //    }
                );
            Log.Info("Route 'MyName.WebApi.Default' has registered.", this);
        }
    }

Configuration Patch

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>

    <api>
      <services>
        <configuration>
          <allowedControllers hint="list:AddController">
            <allowedController desc="MyController">MyNameSpace.MyController ,  MyAssmbly</allowedController>           
          </allowedControllers>
        </configuration>
      </services>
    </api>

    <pipelines>
      <initialize>
        <processor type="MyNameSpace.RegisterWebApiRoutes, MyAssmbly" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']" />
      </initialize>
    </pipelines>
  </sitecore>
</configuration>
  • Could you try removing the ServicesController attribute from the controller? That could be conflicting with your regular routing. – Kasaku Nov 10 '17 at 11:16
  • @Kasaku I tried result is the same – Arbejdsglæde Nov 10 '17 at 11:45
  • Can you confirm your exact Sitecore version? Is SXA related to this at all, as you have tagged it? – Kasaku Nov 10 '17 at 16:01
  • @Kasaku my sitecore version is Sitecore.NET 8.2 (rev. 170614). about SXA I just wonder may be it could have any impediments – Arbejdsglæde Nov 10 '17 at 19:31
1

You might try regist before different pipeline.

Here is an example as shown in below:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
  <pipelines>
    <initialize>
      <processor patch:after="processor[@type='Sitecore.Pipelines.Loader.EnsureAnonymousUsers, Sitecore.Kernel']"
type="LaubPlusCo.Examples.RegisterHttpRoutes, LaubPlusCo.Examples" />
    </initialize>
  </pipelines>
</sitecore>
</configuration>

More details you can find here https://laubplusco.net/implementing-webapi-service-using-servicesapicontroller-sitecore-8/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.