I decorated my ServiceContract
with the WebInvoke
attributes required to publish it as a RESTful service:
[OperationContract]
[WebInvoke(Method = "Authenticate", UriTemplate = "User")]
AuthenticateUserOutput AuthenticateUser(AuthenticateUserInput input);
I then host it with a ServiceRoute
:
RouteTable.Routes.Add(new ServiceRoute("", new ServiceHostFactory(), typeof(MyWcfService)));
The WCF REST help page lists User
as a URI and Authenticate
as a verb
However, if I point our REST test client at it, it returns a 404.
Why can't I use custom verbs?
The solution is to change your <system.webServer>
section at either the IIS level or, my preference, at the web.config level.
I believe this required IIS7.0+ and .net 4.0+ and an Integrated app pool.
Simply add the following element (or to an existing one) under <configuration>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrl-Integrated-4.0"/>
<add name="ExtensionlessUrl-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" responseBufferLimit="0" />
</handlers>
<security>
<requestFiltering>
<verbs allowUnlisted="true"/>
</requestFiltering>
</security>
</system.webServer>
The important changes to note are:
verb="*"
This informs that handler to match any verb
This switches the request filtering to it's most permissive state, by default all verbs are permitted.
Documentation on how to configure this in other versions of IIS:
http://www.iis.net/configreference/system.webserver/handlers http://www.iis.net/configreference/system.webserver/security/requestfiltering/verbs
First thing is,
[WebInvoke(Method = "Authenticate")]
doesn't make any sense to me.
Try,
[WebInvoke(Method = "GET"), UriTemplate = "User")]
then make changes in web.config for restful service.
<endpointBehaviors>
<behavior name="EndPointBehaviour">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
Finally, under service tag add,
<endpoint binding="webHttpBinding" behaviorConfiguration="EndPointBehaviour" name="ServiceEndPoint" contract="WcfService.IService1" />
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.