See if below example helps you:
Service Contract
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet(UriTemplate="Add/{x}/{y}",ResponseFormat=WebMessageFormat.Xml)]
int Add(string x, string y);
}
Service implementation:
public class Service1 : IService1
{
public int Add(string x, string y)
{
return Convert.ToInt32(x) + Convert.ToInt32(y);
}
}
Web config:
<system.serviceModel>
<services>
<service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior">
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="webBehavior" contract="WcfService1.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService1.Service1Behavior">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
Client code:
WebRequest request = WebRequest.Create("http://localhost:2156/Service1.svc/Add/2/3");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Console.WriteLine("Request to add numbers: ");
Console.WriteLine("Request status: " + response.StatusDescription);
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
Console.WriteLine("Response: \n" + responseFromServer);
Console.ReadLine();