i am trying to host a service in IIS which has 2 methods... 1 of them can also be accesed via a simple HTTP-GET request...
This is my config:
<service name="Svc.PaymentService" behaviorConfiguration="DefaultBehavior">
<endpoint address="PaymentService.svc/"
bindingName="Http"
binding="basicHttpBinding"
bindingConfiguration="httpBinding"
contract="Svc.IPaymentService" />
<endpoint address="WEBGETPaymentService.svc/"
behaviorConfiguration="EndpointWebGetBehavior"
binding="webHttpBinding"
contract="Svc.IPaymentService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add ba开发者_高级运维seAddress="http://localhost/MyService/" />
</baseAddresses>
</host>
</service>
the content auf the SVC files is just a simple redirect to my classes
<%@ ServiceHost Service="Svc.PaymentService" %>
<%@ Assembly Name="MyService" %>
and the interface looks like this:
[OperationContract]
string SOAPMethod(
string test);
[OperationContract]
[WebGet(UriTemplate = "asdf?test={test}")]
string RESTfulMethod(
string test);
When i am trying to host the service in IIS and call it via HTTP-GET Request, i always receive a 404...
http://localhost/MyService/WEBGETPaymentService.svc/RESTfulMethod/asdf?test=hello
Anyway, when i try to call the SOAP method via PaymentService.svc it works...
Any ideas what the mistake is?
Thanks
Well, in order to use the webHttpBinding, you need to use the WebServiceHost
(see MSDN docs) in your REST based *.svc file.
So your WEBGETPaymentService.svc should look like this:
<%@ ServiceHost Language="C#" Debug="True"
Service="Svc.PaymentService"
Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
so in that case, it will then use the WebServiceHost
and do all the necessary magic to make REST possible in WCF.
Also check out the WCF REST developer center on MSDN for more info on how to host and use WCF REST services.
精彩评论