Search code examples
c#node.jsnancy

Pass parameters to Nancy Route


I had a Web Service earlier which had a method as below:

public class DxDService : System.Web.Services.WebService
{
   [WebMethod]
   [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
   public string GetSData(string strFirstName, string strLastName, string strDOB, string strSource, SortDetails sortDetails, string ID)
   {
        //manipulate the params and used to return data
   }
}

I consumed this Webservice in my NodeJS application with below piece of code.

var soap=require('soap')

var url = 'http://serverName/DxDService.asmx?wsdl';
var args={'strFirstName':req.actions.firstName,'strLastName':req.actions.lastName, 'strDOB':req.actions.dob, 'strSource':'PtSearch','sortDetails':sort,'ID':''};
soap.createClient(url, function(err, client) {
      client.GetSData(args,function(err, result) {
          req.res = result;
          next();
      });
});

But as part of upgrade we are moving to Windows Service from Web Service which creates a host in local system on start and that host will have functionality of this webservice. I am using Nancy here to start the host. But am confused on the part as how I can receive the parameters in Nancy Routes as I received in web service. Below is what I have in Windows Service as of now.

Service1.cs

private NancyHost host;
protected override void OnStart(string[] args)
{
     var url = "http://127.0.0.1:port";
     this.host = new NancyHost(new Uri(url));
     this.host.Start();
}

RootRoutes.cs which implements NancyModules

public class RootRoutes : NancyModule
{
    public RootRoutes()
    {
        //This should be same as GetSData method in webservice but this acts as Route
        Get["/GetSData"] = parameters =>
        {
            //How can I access params here as I did in webservice method?
            //below is just a sample piece of code showing what returns on browsing
            http://127.0.0.1:port/GetSData

            var test = new
            {
                Name = "Guruprasad Rao",
                Twitter="@kshkrao3",
                Occupation="Software Developer"
            };
            return Response.AsJson(test);
        };
    }
}

How can achieve this? Any idea/help is appreciated.


Solution

  • use string searchTerm = this.Request.Query["term"] to get all the Get method request parameters