<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="ProductsBehavior" name="ProductService.ProductService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/ProductService"/>
</baseAddresses>
</host>
<endpoint address="ProductService.svc" binding="basicHttpBinding"
name="ProductServiceHttpEndPoint" contract="ProductService.IProductService" />
<endpoint address="net.tcp://localhost:8080/TcpProductService"
binding="netTcpBinding" bindingConfiguration="" name="ProductServiceTcpEndPoint"
contract="ProductService.IProductService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ProductsBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
When ever ServiceHost is instantiated, a separate listener for each endpoint will be created. Nothing more needed from service host.
Move on to the client application
Open App.config, and in the client section, add a new tcp end point
<client>
<endpoint address="http://localhost:8000/ProductService/ProductService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProductService"
contract="ProdServiceReference.IProductService" name="BasicHttpBinding_IProductService" />
<endpoint address="net.tcp://localhost:8080/TcpProductService"
binding="netTcpBinding" bindingConfiguration="" contract="ProdServiceReference.IProductService"
name="NetTcpBinding_IProductService" />
</client>
Move on to your code behind file, to execute service through newly configured Tcp connection, write the following code and invoke it in the place of your choice.
private void OpenTcpClient()
{
ProductServiceClient proxy =
new ProductServiceClient("NetTcpBinding_IProductService");
List
foreach (string prod in lstProducts)
{
Console.WriteLine(prod);
}
}
No comments:
Post a Comment