WCF 错误 "there was no endpoint listening at ..."
WCF error "there was no endpoint listening at ..."
我正在创建我的第一个 WCF 应用程序。当它们在同一台计算机上时,客户端可以与主机通信,但从 LAN 上的其他计算机失败。两者都是控制台应用程序。
这是我的代码和配置。
客户端配置:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ICalculator" />
</wsHttpBinding>
</bindings>
<client>
<endpoint name="WSHttpBinding_ICalculator"
address="http://192.168.100.6:8000/ServiceModelSamples/Service/CalculatorService"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_ICalculator"
contract="ServiceReference1.ICalculator">
<identity>
<userPrincipalName value="saumitra\skpaul" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
主机代码:
class Program
{
static void Main(string[] args)
{
// Step 1 Create a URI to serve as the base address.
Uri baseAddress = new Uri("http://Localhost:8000/ServiceModelSamples/Service");
// Step 2 Create a ServiceHost instance
ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress);
try
{
// Step 3 Add a service endpoint.
selfHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "CalculatorService");
// Step 4 Enable metadata exchange.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
// Step 5 Start the service.
selfHost.Open();
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
// Close the ServiceHostBase to shutdown the service.
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine("An exception occurred: {0}", ce.Message);
selfHost.Abort();
}
}
}
首先确保从客户端使用的地址是服务器的正确位置。您的代码当前被硬编码到目标位置...
<endpoint address="http://192.168.100.6:8000/
...但是服务器实际上 运行 在 192.168.100.6 上吗?
你可以从 this post
中得到一个想法
你也可以使用Socket编程。 Here 是多客户端、双向通信套接字编程的一个很好的例子。
我正在创建我的第一个 WCF 应用程序。当它们在同一台计算机上时,客户端可以与主机通信,但从 LAN 上的其他计算机失败。两者都是控制台应用程序。
这是我的代码和配置。
客户端配置:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ICalculator" />
</wsHttpBinding>
</bindings>
<client>
<endpoint name="WSHttpBinding_ICalculator"
address="http://192.168.100.6:8000/ServiceModelSamples/Service/CalculatorService"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_ICalculator"
contract="ServiceReference1.ICalculator">
<identity>
<userPrincipalName value="saumitra\skpaul" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
主机代码:
class Program
{
static void Main(string[] args)
{
// Step 1 Create a URI to serve as the base address.
Uri baseAddress = new Uri("http://Localhost:8000/ServiceModelSamples/Service");
// Step 2 Create a ServiceHost instance
ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress);
try
{
// Step 3 Add a service endpoint.
selfHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "CalculatorService");
// Step 4 Enable metadata exchange.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
// Step 5 Start the service.
selfHost.Open();
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
// Close the ServiceHostBase to shutdown the service.
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine("An exception occurred: {0}", ce.Message);
selfHost.Abort();
}
}
}
首先确保从客户端使用的地址是服务器的正确位置。您的代码当前被硬编码到目标位置...
<endpoint address="http://192.168.100.6:8000/
...但是服务器实际上 运行 在 192.168.100.6 上吗?
你可以从 this post
中得到一个想法你也可以使用Socket编程。 Here 是多客户端、双向通信套接字编程的一个很好的例子。