I am using WCF REST Start kit to build a RESTFul service. I defined a service like this:
namespace MyNS {
[ServiceBehavior(IncludeExceptionDetailInFaults = true,
InstanceContextMode = InstanceContextMode.Single,
ConcurrencyMode = ConcurrencyMode.Single)]
[AspNetCompatibilityRequirements(
RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService : MyCollectionServiceBase, IMyCollectionServiceBase
{...}
}
MyCollectionServiceBase and IMyCollectionSeviceBase are defined like this:
namespace MyNS.Contract {
[ServiceContract]
public interface IMyCollectionServiceBase<TItem> where TItem : class
{...}
// COllectionServiceBase is an abstract class in
// Microsoft.ServiceModel.Web.SpecializedServices
public abstract class MyCollectionServiceBase<TItem> :
CollectionServiceBase<TItem>
where TItem : class
{...}
}
and here is a section of service in my Web.config
<serviceBehaviors>
...
<behavior name="MyNS.MyService1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
...
<service behaviorConfiguration="MyNS.MyService1Behavior"
name="MyNS.MyService1">
<endpoint address="" binding="wsHttpBinding"
contract="MyNS.IMyService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
When I test my service by using “http://localhost:1290/MyService.svc/“, I got error message saying:
The contract name 'MyNS.Contract.IMyCollectionServiceBase' could not be found
in the list of contracts implemented by the service 'MyService'.
I am not sure if the endpoint is not matched or something is missing?
You should read the An Introduction To RESTful Services With WCF article (MSDN Magazine, January 2009 issue) for an introduction.
Your current service config is using
wsHttpBindingwhich is not REST (but SOAP instead) – you need ot usewebHttpBindinginstead.Also, in order to have a RESTful service, you need to decorate your service operations with either a
[WebGet]or a[WebInvoke]attribute and optionally provide parameters to define how exactly that HTTP URI should be called and should react.