Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在没有web.config或httpModule的情况下定义端点?_C#_.net_Wcf_Rest - Fatal编程技术网

C# 如何在没有web.config或httpModule的情况下定义端点?

C# 如何在没有web.config或httpModule的情况下定义端点?,c#,.net,wcf,rest,C#,.net,Wcf,Rest,我想创建一个HTTPhandlers的RESTful应用程序,而不必通过在web.config中创建一个条目来定义每个端点,我想要将属性附加到类构造函数的样式,例如: public class obj : IHttpHandler { [WebGet(UriTemplate = "/accounts/{id}")] public obj(string id) { // this is just an eg, it worild normally include cachin

我想创建一个HTTPhandlers的RESTful应用程序,而不必通过在web.config中创建一个条目来定义每个端点,我想要将属性附加到类构造函数的样式,例如:

public class obj : IHttpHandler
{
  [WebGet(UriTemplate = "/accounts/{id}")]
  public obj(string id)
  {
     // this is just an eg, it worild normally include caching and 
     // a template system
     String html = File.ReadAllText("/accounts/accounts.htm");
     html.replace("id", id);
     httpcontext.current.response.write(html)
  }
}
而不是

<httpHandlers>
      <clear />
      <add verb="GET" path="/accounts/*" type="MyApp.obj" />
</httphandlers>

按照我现在的做法,我在web.config中有100个端点:(我宁愿在类中定义它们。我也不想创建额外的文件(.asmx)。我想要一个只包含.htm文件和令牌以及.cs文件的应用程序


谢谢!

您可以使用自定义ServiceHost自动注册端点等,该自定义ServiceHost会覆盖ApplyConfiguration()方法,然后该方法会虚拟化配置,使其不必位于web.config文件中


。它不能完全满足您的要求,但它说明了虚拟化配置的概念。

您可以使用自定义ServiceHost自动注册端点等,该自定义ServiceHost会覆盖ApplyConfiguration()方法,然后虚拟化配置,使其不必位于web.config文件中


。它不能完全满足您的要求,但它说明了虚拟化配置的概念。

考虑修改代码段:“public call obj”?“public obj(字符串id)”我正在考虑修改BE的问题:哪种方法负责解析请求URL并选择哪个HTPHONDANER来实例化。考虑修改代码片段:“公共调用Objo”?“公共Objo(String ID)”。?我正在考虑修改问题be:哪个方法负责解析请求URL并选择要实例化的httphandler。这看起来像是要走的路,ServiceHostBase.AddServiceEndpoint方法(字符串,绑定,Uri)谢谢!这看起来像是要走的路,ServiceHostBase.AddServiceEndpoint方法(字符串、绑定、Uri)谢谢!