I have created a test WCF service WcfSampleLib with contract as IWcfSampleLib and ny service class is clsWcfSampleLib.
namespace WcfSampleLib
{
public class clsWcfSampleLib:IWcfSampleLib
{
public string getMsg(string name)
{
return " HI " + name;
}
}
[ServiceContract]
public interface IWcfSampleLib
{
[OperationContract]
string getMsg(string name);
}
}
Now I have added a window form application to host my WCF. I have created a App.config as
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Beh">
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://{server}:9097"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name ="WcfSampleLib.clsWcfSampleLib" behaviorConfiguration="Beh">
<endpoint address="http://{server}:9096/SomeName" binding="basicHttpBinding" contract ="WcfSampleLib.IWcfSampleLib"/>
<endpoint address="net.tcp://{server}:9095/SomeName1" binding="netTcpBinding" contract ="WcfSampleLib.IWcfSampleLib"/>
</service>
</services>
</system.serviceModel>
</configuration>
I have two endpoints to use WCF from two different clients with different end point. I have added following lines of code in Form1_Load event of Host Application
host = new ServiceHost(typeof(WcfSampleLib.clsWcfSampleLib));
host.Open();
MessageBox.Show("started");
Now I can add reference of service with http://{server}:9097 only. Is there any way so that I can use both endpoints with different URL means net.tcp://{server}:9095/SomeName1 and http://{server}:9096/SomeName