另一个WCF没有使用basicHTTPBinding监听的端点

时间:2014-02-03 06:39:15

标签: wcf endpoint basichttpbinding

我不是WCF的专家,我希望有人会指出为什么我的基本“hello world”WCF服务在使用简单的交叉电缆在单独的联网计算机上进行测试时不起作用。但是,它在1台PC上测试时效果很好。 2 PC互相通话没有任何问题,因为两台PC可以相互ping通,并且两台PC的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(如果存在)。

Client Program.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();
    }
  }

客户端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>

Server Program.cs

  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();
    }
  }

Server App.config

<?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>

1 个答案:

答案 0 :(得分:1)

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

ipconfig -all
相关问题