I am building a web service using WCF. This service has to support REST.
Here is what I did so far:
I configured the app with a baseAddress, the mex endpoint and an additional endpoint which has a webhttpbinding.
Here is the service configuration:
<service name="ServiceLibrary.Service" behaviorConfiguration="myServiceBehavior">
<endpoint
address=""
behaviorConfiguration="webHttp"
binding="webHttpBinding" bindingConfiguration=""
contract="ServiceLibrary.IEvalService" >
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/sdata/myApp/myContract/-/"/>
</baseAddresses>
</host>
</service>
And here is the behavior configuration:
<serviceBehaviors>
<behavior name="myServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp/>
</behavior>
</endpointBehaviors>
I am setting up a service contract like this:
[ServiceContract]
public interface IEvalService
{
[OperationContract]
[WebGet(UriTemplate = "/employees('{MDNr}:{ANNr}')")]
Atom10ItemFormatter GetEmployeeByPK(string MDNr, string ANNr);
[OperationContract]
[WebGet]
string employees(string queryString);
}
And I am handling the operation contract in a separate class:
public class Service : IEvalService
{
public Atom10ItemFormatter GetEmployeeByPK(string MDNr, string ANNr){return Employee.GetEmployeeByPK(MDNr, ANNr);}
public string employees(string queryString)
{
System.Diagnostics.Debug.WriteLine("Query: " + queryString);
return queryString;
}
Both methods get called after executing the GET method.
I am calling the first one like this:
http://localhost:8732/sdata/myApp/myContract/-/employees('3:37')
It works perfectly, giving me the IDs, etc.
The second one I am calling like this:
http://localhost:8732/sdata/myApp/myContract/-/employees?where=name eq 'bla'
And here is where the trouble starts. The Method employees is getting called, but it receives no string. And I don’t know why. This is exactly the same code, like in those tutorials, I just changed the names…
Does anyone see the mistake I obviously made? I would really appreciate any help.
One more thing: I am working with .Net 4.0 and am running this over the debugger so I can call the urls via firefox rest client? This is a service library project.
Try to change the parameter’s name:
or change the url:
Answer to your comment: