我还在学习,我在使用BasicHttpBinding将同一网络中的另一台连接的计算机连接到我的简单WCF服务时遇到问题 .

服务器:

static void Main(string[] args)
    {
        string  endPointAddress = "http://localhost:9942/ServiceTest";
        Uri baseAddress = new Uri(endPointAddress);
        var host = new ServiceHost(typeof(SampleService), baseAddress);
        BasicHttpBinding httpBinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
        host.AddServiceEndpoint(typeof(ISampleService), httpBinding, "ISampleService");
        host.Open();
        Console.WriteLine("Service up and running at:");
        foreach (var ea in host.Description.Endpoints)
        {
            Console.WriteLine(ea.Address);
        }
        Console.ReadLine();

客户:

public class ProxyTestService : ClientBase<ISampleService>, ISampleService   {
   public ProxyTestService(string address)
       :base (new BasicHttpBinding(BasicHttpSecurityMode.None),new EndpointAddress($"http://{address}:9942/ServiceTest/ISampleService"))
   {}
   public DateTime GetServerTime()
   {
       return base.Channel.GetServerTime();
   }}

当我在计算机上检查主机运行的位置时,它很好(address = localhost) .

但是,当我从网络中的另一台计算机(地址= IPComputerHost)连接时,存在以下问题:

在http://192.168.1.111:9942/ServiceTest/ISampleService上没有可以接受该消息的 endpoints . 这通常是由错误的地址或SOAP操作引起的 . 有关更多详细信息,请参阅InnerException(如果存在) . InnerException:无法连接到远程服务器

您已尝试为不支持.Net Framing的服务创建 Channels . 您可能遇到HTTP endpoints .

当我使用NetTcpBinding时,一切都是正确的 . BasicHttpBinding有什么不同?