将参数传递给Nancy Route

时间:2016-02-24 08:29:26

标签: c# node.js nancy

我之前有一个Web服务,它有一个方法如下:

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
   }
}

我使用下面的代码在我的Webservice应用程序中使用了NodeJS

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();
      });
});

但是作为升级的一部分,我们将从Web服务迁移到Windows服务,该服务在启动时在本地系统中创建主机,并且该主机将具有此webservice的功能。我在这里使用 Nancy 来启动host。但我觉得我在网络服务中收到Nancy Routes中的参数时会感到困惑。以下是我目前在Windows Service中所拥有的内容。

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();
}
实现 NancyModules

RootRoutes.cs

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);
        };
    }
}

怎么能实现这个目标?任何想法/帮助表示赞赏。

1 个答案:

答案 0 :(得分:2)

使用字符串searchTerm = this.Request.Query["term"]获取所有Get方法请求参数