简体   繁体   中英

Customize WCF Service endpoint address in IIS Host

使用 IIS 托管时是否可以更改 WCF 服务上的终结点地址,我当前只是指向 svc 文件,但我想使用 RESTful 命令?

Discussed in Overview of REST in WCF . They point to the WCF REST Starter Kit .

The WCF REST Starter Kit is a set of .NET Framework classes and Visual Studio features and templates that enable users to create and access REST-style Windows Communication Foundation (WCF) services. These services are based on the WCF web programming model available in .NET 3.5 SP1. The starter kit also contains the full source code for all features, detailed code samples, and unit tests.

WCF in .NET 4 will support so-called file-less activation, which will allow you to define any arbitrary URL, and map that to a WCF service.

Check out the Developer's Introduction to WCF 4 for some info, or read this blog post specifically on file-less activation.

Basically, in WCF 4, you can add an entry to your web.config:

<serviceHostingEnvironment  >
   <serviceActivations>
       <add factory="System.ServiceModel.Activation.ServiceHostFactory" 
            relativeAddress="/Services/MyService" 
            service="MyServiceClass"/>
   </serviceActivations>
 </serviceHostingEnvironment>

and thus, pointing your browser to http://YourServer/Services/MyService would then activate that particular service.

Ron Jacobs also has an interesting approach for REST services , where he registers a route to avoid the *.svc file - he explains this for the WCF Data Services, but it's my feeling, this should work for all WCF REST services, really. But it's a .NET 4 only feature, also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM