Я сделал демо и обнаружил, что во фрагменте кода нет проблем, я предлагаю вам опубликовать более подробную информацию о вашем проекте.
Вот мой консольный проект, желаю, чтобы он был вам полезен.
Сервер.
class Program
{
static void Main(string[] args)
{
using (ServiceHost sh=new ServiceHost(typeof(MyService)))
{
sh.Open();
Console.WriteLine("Service is ready....");
Console.ReadLine();
sh.Close();
}
}
}
[ServiceContract]
public interface IService
{
[OperationContract]
int Mult(int x, int y);
}
public class MyService : IService
{
public int Mult(int x, int y)
{
OperationContext oc = OperationContext.Current;
Console.WriteLine(oc.Channel.LocalAddress.Uri);
return x * y;
}
}
App.config
<system.serviceModel>
<services>
<service name="WCFServer1.MyService" behaviorConfiguration="mybehavior">
<endpoint address="HelloService" binding="basicHttpBinding" contract="WCFServer1.IService"></endpoint>
<endpoint address="HelloService" binding="netTcpBinding" contract="WCFServer1.IService"></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:5110"/>
<add baseAddress="net.tcp://localhost:5120"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mybehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Результат.
Не стесняйтесь, дайте мне знать, если есть что-то, с чем я могу помочь.