WCF删除.SVC延伸 [英] WCF removing .svc extention

查看:259
本文介绍了WCF删除.SVC延伸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够通过以下职位ServiceRoute添加到我的WCF .NET 4.0的服务与.svc扩展名:

I'm able to add a ServiceRoute to my WCF .net 4.0 service with a .svc extension by following these posts:

  1. 后1
  2. <一个href="http://stackoverflow.com/questions/3292908/eliminate-the-svc-in-the-url-of-a-wcf-4-service-using-routes">Post 2
  1. Post 1
  2. Post 2

然而如何删除了.SVC延期?

我的实际服务的文件被称为 Catalog.svc

My actual service file is called Catalog.svc

和下面的这些职位后,我能够使用访问相同的服务 csw.svc

And after following those posts i'm able to access the same service using csw.svc

我Global.asa.cs:

my Global.asa.cs:

protected void Application_Start(object sender, EventArgs e)
{
    RegisterRoutes(RouteTable.Routes);
}

private void RegisterRoutes(RouteCollection routes)
{
    routes.Add(new ServiceRoute("csw.svc", new WebServiceHostFactory(), typeof(CSW_ebRIM_WebService.Catalog)));
}

我的web.config:

my Web.config:

...
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" >
   <serviceActivations>
      <add factory="System.ServiceModel.Activation.ServiceHostFactory"
           relativeAddress="~/csw.svc"
           service="CSW_ebRIM_WebService.Catalog"/>
   </serviceActivations>          
</serviceHostingEnvironment>
<system.webServer>
   <modules runAllManagedModulesForAllRequests="true">
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
   </modules>
   <handlers>
       <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd"/>
   </handlers>
</system.webServer>

但是,如果我删除 .SVC 扩展来自全球和的web.config 获取和错误他说:

However if I remove the .svc extension from both the global and the web.config I get and error saying:

注册relativeAddress第〜/ CSW   system.serviceModel / serviceHostingEnvironment / serviceActivati​​ons中   配置文件不具有扩展名

The registered relativeAddress '~/csw' under section 'system.serviceModel/serviceHostingEnvironment/serviceActivations' in configuration file does not have an extension.

如果我把后面的 .SVC 扩展上的的web.config ,只有从全局我删除得到:

If i put back the .svc extension on the web.config and only remove it from the global I get:

值不能为空。   参数名:合约

Value cannot be null. Parameter name: contract

说明:执行当前Web的执行过程中发生未处理的异常   请求。请检查堆栈跟踪有关的详细信息   错误以及它起源于code。

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

异常详细信息:System.ArgumentNullException:值不能为空。   参数名:合约

Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: contract

怎么办?我怎样才能删除 .SVC 扩展?

What gives? How can I remove the .svc extension?

推荐答案

罗恩·雅各布斯对这一主题的伟大的职位 - 你需要使用 ServiceRoute 来实现你要找的:

Ron Jacobs has a great post on the topic - you need to use a ServiceRoute to achieve what you're looking for:

  • <一个href="http://blogs.msdn.com/b/rjacobs/archive/2010/04/05/using-system-web-routing-with-data-services-odata.aspx">Using与数据服务System.Web.Routing(OData的)

当他显示了他的后续帖子,<一个href="http://blogs.msdn.com/b/rjacobs/archive/2010/04/06/wcf-data-services-and-serviceroute.aspx">WCF数据服务和ServiceRoute ,由此产生的服务文档确实也反映了变化,而显示 .SVC 延伸服务URL。

As he shows in his follow-up post, WCF Data Services and ServiceRoute, the resulting service document does indeed also reflect the change and shows the service URL without the .svc extension.

这东西需要ASP.NET路由支持,这是完全美元的.NET 4 P $ psent(并且可以在.NET用螺栓固定在3.5 SP1,如果需要的话)

This stuff requires the ASP.NET routing support, which is fully present in .NET 4 (and can be bolted on in .NET 3.5 SP1, if needed)

这篇关于WCF删除.SVC延伸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆