另一个WCF无端点侦听使用basicHTTPBinding

另一个WCF无端点侦听使用basicHTTPBinding,wcf,endpoint,basichttpbinding,Wcf,Endpoint,Basichttpbinding,我不是WCF方面的专家,我希望有人能指出为什么我最基本的“hello world”WCF服务在使用简单的交叉电缆在单独的联网计算机上进行测试时无法工作。但是,当在1台电脑上测试时,它可以完美地工作。2台电脑相互交谈没有问题,因为两台电脑都可以相互ping,并且两台电脑的windows7防火墙都已禁用。客户端和服务器应用均使用管理员权限运行 服务器PC的ip为10.0.0.25 。我还测试了使用adsl调制解调器/交换机连接PC的网络,但使用以太网和wifi连接也得到了相同的结果。然而,当我在我公

我不是WCF方面的专家,我希望有人能指出为什么我最基本的“hello world”WCF服务在使用简单的交叉电缆在单独的联网计算机上进行测试时无法工作。但是,当在1台电脑上测试时,它可以完美地工作。2台电脑相互交谈没有问题,因为两台电脑都可以相互ping,并且两台电脑的windows7防火墙都已禁用。客户端和服务器应用均使用管理员权限运行

服务器PC的ip为10.0.0.25

。我还测试了使用adsl调制解调器/交换机连接PC的网络,但使用以太网和wifi连接也得到了相同的结果。然而,当我在我公司的无线网络上尝试完全相同的场景时,它确实起作用,这可能提供了一个线索。 在服务器应用程序运行的情况下,从客户端PC打开web浏览器,输入以下URL。这表示服务正在运行

http://10.0.0.25:1235/MySecondService
当我在1台PC上同时运行客户端和服务器时,它可以工作

错误: 在
http://10.0.0.25:1235/MySecondService
可以接受该消息。这通常是由不正确的地址或SOAP操作引起的。有关更多详细信息,请参阅InnerException(如果存在)

客户端程序.cs

   class Program
   {
    static void Main(string[] args)
    {
      string serviceURL = "http://10.0.0.25:1235/MySecondService";

      ChannelFactory<IMySecondService> channelFactory1 =
          new ChannelFactory<IMySecondService>(
              new BasicHttpBinding(),
              new EndpointAddress(serviceURL));

      IMySecondService mySecondService = channelFactory1.CreateChannel();

      Console.WriteLine("This test console application is a client for the MyFirstService WCF service");
      Console.WriteLine(string.Format("It tries to use the service at address: {0}", serviceURL));
      Console.WriteLine();
      Console.Write("Write text to get number of words: ");

      string s = Console.ReadLine();
      int numberWords = mySecondService.GetNumberWords(s);

      Console.WriteLine(string.Format("Number of words: {0}", numberWords));

      s = Console.ReadLine();
    }
  }
  class Program
  {
    static void Main(string[] args)
    {
      ServiceHost serviceHost1 = new ServiceHost(typeof(MySecondService));

      serviceHost1.Open();

      Console.WriteLine("This console application hosts the MySecondService WCF service at address " +  serviceHost1. BaseAddresses[0]. ToString());      

      Console.WriteLine("Press ENTER to finish hosting");
      Console.ReadLine();

      serviceHost1.Close();
    }
  }
服务器App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IMySecondService" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://10.0.0.25:1235/MySecondService" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IMySecondService" contract="ServiceReference1.IMySecondService"
                name="BasicHttpBinding_IMySecondService" />
        </client>
    </system.serviceModel>
</configuration>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="SecondService.MySecondService"
               behaviorConfiguration="">
        <host>
          <baseAddresses>
            <add baseAddress="http://10.0.0.25:1235/MySecondService"/>
          </baseAddresses>
        </host>
        <endpoint address=""
                  binding="basicHttpBinding"
                  contract="SecondService.IMySecondService" />
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>    
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>       
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

由于它在您尝试的一个网络(您的工作网络)上工作,而不是在您的家庭网络上,因此我猜您使用的IP地址仅在该网络上有效。当您在其他网络(如家庭wifi)上时,您可能正在使用不同的NIC和/或被分配不同的IP。尝试转到windows中的命令行,并使用此命令检查所有NIC的IP地址

ipconfig -all

当我在网络之间切换时,由于DHCP,IP地址确实发生了变化。为了适应这一点,我在代码中做了相关的修改。另外,在两个网络之间切换时,我只使用wifi端口来确保两个测试之间的差异尽可能小。我已经设法解决了这个问题。正是Internet explorer中的代理设置让我如此悲痛。我公司的网络使用代理服务器访问互联网。我通常使用mozilla firefox访问互联网。因此,当我在网络之间切换时,我会在firefox中更改代理设置,这样我就可以访问互联网了。看起来WCF使用了“Internet Explorer”的设置,很明显,当我在不同的网络之间切换时,这些设置没有改变。所以底线是,在使用WCF时,确保IE中的代理搜索是正确的。