namespace CalculatorServiceContract
{
[ServiceContract]
public interface ICalculator
{
[OperationContract]
int Add (int a, int b);
}
}
namespace CalculatorService
{
// Implementation of CalculatorServiceContract
public class CalculatorService : ICalculator
{
public int Add(int a, int b)
{
return a + b;
}
}
}
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_AtServer"/>
</basicHttpBinding>
</bindings>
<services>
<service name="CalculatorService">
<endpoint address="http://localhost/CalculatorSample/CalculatorService.svc"
binding="basicHttpBinding" bindingConfiguration="basicHttpBinding_AtServer"
contract="CalculatorServiceContract.ICalculator"/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.serviceModel>
<client>
<endpoint binding="basicHttpBinding"
address="http://localhost/CalculatorSample/CalculatorService.svc"
contract="CalculatorServiceContract .ICalculator"
name="basicHttpBind"/>
</client>
</system.serviceModel>
public static void main(string args[])
{
/*Create a ChannelFactory instance of type ICalculator.
You need to create an channel by specifying the binding name which is defined at web.config in client project which is shown above.
So the the below code will create an endpoint listener*/
ICalculator calc = new ChannelFactory<ICalculator>("basicHttpBind").CreateChannel();
int A = calc.Add(12, 15);
Console.WriteLine(A);
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)