I have a WCF service with custom binding, hosted in IIS (IIS Express in development) with following service contract:
[ServiceContract]
public interface IServer
{
[OperationContract]
StreamCollection GetStreams(Guid poolKey);
[OperationContract]
PoolCollection GetPools();
[OperationContract]
StreamEntity GetStream(Guid poolKey, string localIndex);
}
It works OK (from client and also I can see it’s metadata discovered ok in WCFTestClient).
I have to expose its functionality as REST, so I created a new contract as below
[ServiceContract]
public interface IRestServer
{
[OperationContract(Name="GetStreamsREST")]
[WebGet(UriTemplate = "pool/{poolKey}/streams")]
StreamCollection GetStreams(string poolKey);
[OperationContract(Name = "GetPoolsREST")]
[WebGet(UriTemplate = "pools")]
PoolCollection GetPools();
[OperationContract(Name = "GetStreamREST")]
[WebGet(UriTemplate = "pool/{poolKey}/stream/{localIndex}")]
StreamEntity GetStream(string poolKey, string localIndex);
}
I have both interfaces implemented in the same service class.
The web.config file is
<behaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="CustomBinding">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="655360" />
</binding>
</customBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehavior" name="MyServ.Server.Server">
<endpoint address="" binding="customBinding" bindingConfiguration="CustomBinding" contract="MyServ.Server.IServer" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="rest" behaviorConfiguration="webHttp" binding="webHttpBinding" contract="MyServ.Server.IRestServer" />
</service>
</services>
However, when I browse to access the service using rest, witha url like
http://localhost:<myport>/Service.svc/pools
http://localhost:<myport>/Service.svc/pool/somekey/streams
http://localhost:<myport>/Service.svc/pool/somekey/streams
I get error 404.
I put a break-point in some methods and attached debugger to IIS process, but it seems nothing gets called.
If I check the service metadata with WCFTestClient, it just sees IService, but not IRestService. Is this normal? EDIT: Yes, it seems it is (check this)
Thanks for any suggestion.
Thanks all for all suggestions.
However, I solved the issue finally.
The problem is I don’t know still what was the problem, but I decided to take a different and more “clean” way.
So what I did was to create a different service SVC file, RestServer, where I implemented the REST methods
And I modified the settings in web config to have two different services, one for original one (pure WCF) and one for REST one, as below
And this did the trick.
Actually, I should use this approach from the very beginning, to comply with single responsability principle …