This works:
[ServiceContract]
public interface IService
{
[WebInvoke(Method = "POST", UriTemplate = "/ModifyCustomer", RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
Customer ModifyCustomer(Customer customer);
}
public class Service : IService
{
public Customer ModifyCustomer(Customer customer)
{
customer.Age += 1;
return customer;
}
}
public class Customer
{
public string Name { get; set; }
public int Age { get; set; }
}
And self-hosting like:
var webServiceHost = new WebServiceHost(typeof(Service),
new Uri("http://localhost:12345"));
webServiceHost.AddServiceEndpoint(typeof(IService), new WebHttpBinding(),"");
webServiceHost.Open();
In Postman:
And in IIS Express with the following config:
<system.serviceModel>
<services>
<service name="RestServiceTest.Service" behaviorConfiguration="myServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="RestServiceTest.IService" behaviorConfiguration="myEndpointBehavior">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="myEndpointBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
Result from postman: