我在IIS 7.5上使用WCF 4,并希望从我所有RESTful服务的URL中删除默认的.svc扩展名.我已经看到了使用Url Rewrite Module和IHttpModule记录的方法,但我不想采用这些方法.
我模糊地熟悉ASP.NET MVC中引入的Routes的概念,据我所知,它们现在已经从Net4中作为System.Web.Routing从MVC中抽象出来.但是在查看文档时,我需要将一个Global.asax文件添加到我的项目中,我并不是真的热衷于此.有没有其他方法来处理这个?
我也看过基于配置的激活功能,但这似乎只是消除了.svc文件,但仍然要求我在我的服务网址中使用.svc.
任何人都可以在这里总结我的选择,因为我的网址中不需要.svc吗?
我正在创建一个WCF4服务,其REST和SOAP端点将在IIS 7.5中托管.我以WCF4 REST模板为例.但是到目前为止我对我的设置有几个问题.
这是我的webconfig
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<behaviors>
<endpointBehaviors>
<behavior name="REST">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MEXGET">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MEXGET" name="Project.WebService.VehicleService">
<endpoint
address=""
behaviorConfiguration="REST"
binding="webHttpBinding"
contract="Project.WebService.IVehicleService" />
<endpoint
address="soap"
binding="basicHttpBinding"
contract="Project.WebService.IVehicleService" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
我删除了standardEndpoints部分并添加了自己的端点.没有.svc文件,因为我在global.asax中设置了路由,如下所示
private void RegisterRoutes()
{
RouteTable.Routes.Add(new ServiceRoute("VehicleService", new WebServiceHostFactory(), typeof(VehicleService)));
}
Run Code Online (Sandbox Code Playgroud)
可以通过http:// localhost:1313/ServiceTest/VehicleService/help访问帮助页面
我还使用WCF测试客户端访问http:// localhost:1313/ServiceTest/VehicleService/mex ,它显示了SOAP端点的元数据
但是,如何检索服务的WSDL?
使用svc文件,我可以在http:// localhost:1313/ServiceTest/VehicleService.svc找到wsdl ?wsdl但是我没有.svc文件.我也无法在http:// localhost:1313/ServiceTest/VehicleService?wsdl或http:// localhost:1313/ServiceTest/VehicleService/soap?wsdl …
我在IIS上托管了WCF服务.出于商业原因,我不能发布此实例的公共URL,但我相信你会得到我的意思:
问题是,为了到达我的端点,似乎我已经包含Service.svc了路径段的一部分,即,我必须使用这样的URL:
http://<domain>/<app-name>/Service.svc/<relative-path>
我怎么能避免这个?我的意思是,我想通过以下方式访问我的服务:
http://<domain>/<app-name>/<relative-path>
当我在开发过程中自我托管服务时,我完全能够做到这一点.
最后,但这不是那么超然,浏览到http://<domain>/<AppName>/Service.svcURL会显示标准服务信息页面:
有没有办法可以防止这种情况发生?
