WCF删除.svc扩展名 [英] WCF removing .svc extension

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

问题描述

我可以通过以下这些帖子将ServiceRoute添加到带有.svc扩展名的WCF .net 4.0服务中:

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. 帖子2

但是如何删除".svc"扩展名?

我的实际服务文件被称为 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>

但是,如果我同时从全局和 web.config 中都删除了 .svc 扩展名,则会出现错误:

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/serviceActivations"配置文件没有扩展名.

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:

值不能为null.参数名称:合同

Value cannot be null. Parameter name: contract

说明:在执行当前Web期间发生未处理的异常要求.请查看堆栈跟踪以获取有关以下内容的更多信息:错误及其在代码中的起源.

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:值不能为null.参数名称:合同

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

有什么作用?如何删除 .svc 扩展名?

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

推荐答案

Ron Jacobs关于该主题的精彩文章-您需要使用 ServiceRoute 来实现所需的目标:

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

如他在后续帖子中所示,

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中完全存在(如果需要,可以将其固定在.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天全站免登陆