通过以下文章,我可以将一个ServiceRoute添加到我的WCFW4.0服务中,并有一个ServiceRoute扩展:
然而,如何删除".svc“扩展呢?
我的实际服务文件称为Catalog.svc。
在完成这些文章之后,我可以使用csw.svc访问相同的服务
我的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:
...
<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中删除,我会得到并错误地说:
配置文件中节'system.serviceModel/serviceHostingEnvironment/serviceActivations‘下的已注册relativeAddress '~/csw’没有扩展名。
如果我将.svc扩展放回web.config上,并且只将其从全局中删除,则会得到:
值不能为空。参数名称:合同 描述:在执行当前web请求时发生了未处理的异常。请查看堆栈跟踪以获得有关错误的更多信息,以及它起源于代码的位置。 异常详细信息: System.ArgumentNullException: Value不能为空。参数名称:合同
怎么回事?如何删除.svc扩展?
发布于 2011-09-09 05:11:07
罗恩·雅各布斯( Ron )在这个话题上发表了一篇很棒的文章--你需要使用一个ServiceRoute来实现你想要的目标:
正如他在他的后续文章WCF数据服务和ServiceRoute中所显示的那样,结果服务文档实际上也反映了更改,并且显示了没有.svc扩展的服务URL。
这需要ASP.NET路由支持,它完全存在于.NET 4中(如果需要,可以在.NET 3.5 SP1中使用)
https://stackoverflow.com/questions/7354616
复制相似问题