1

我正在尝试实现在NetFX Harmonics 中找到的可扩展 wcf 解决方案:创建流线型、简化且可扩展的 WCF 连接

所以我的解决方案有 4 个项目

  • Contact.Service(服务和数据合同)
  • Contact.ServiceImpl(HostFactory 和 Service 本身)
  • Contact.ServiceHost(Web.config 和 Person.svc)
  • 联系.ServiceClient

Contact.ServiceClient 具有实际调用服务的 App.config 和 Program.cs。

应用程序配置

<configuration> 
  <appSettings>
    <add key="PersonServiceActiveEndpoint" value="PersonServiceBasicHttpBinding" />
  </appSettings>    
  <system.serviceModel>
    <client>
      <endpoint name="PersonServiceBasicHttpBinding"
                address="http://localhost:1031/Person.svc"
                binding="basicHttpBinding"
                contract="Contact.Service.IPersonService" />
    </client>
  </system.serviceModel>  
</configuration>

程序.cs

  BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
            EndpointAddress endpointAddress = new EndpointAddress("http://localhost:1031/Person.svc");
            IPersonService personService = new ChannelFactory<IPersonService>(basicHttpBinding, endpointAddress).CreateChannel();

            Person person = personService.GetPersonData("F488D20B-FC27-4631-9FB9-83AF616AB5A6");
            Console.WriteLine(person.FirstName);

当我尝试运行此示例时,抛出异常:

http://localhost:1031/Person.svc上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。

PS Person.svc 在我的 Contact.ServiceHost 项目中

<%@ ServiceHost Service="Contact.Service.PersonService" %>
4

1 回答 1

0

服务主机的配置是什么?听起来像是两个问题之一:

  • 服务主机未设置为侦听同一端口。
  • 主机应用程序根本没有运行

我想通过检查服务主机项目的 web.config,您可能会发现它正在侦听不同的端口,或者根本没有运行,因此没有侦听。

Visual Studio 主机是否启动并托管服务?您通常会在时钟旁边的通知区域中看到一个小的“toast”弹出窗口,说明主机正在运行,您可以看到它在哪个端口上运行。如果这没有发生,那么您可能需要对其进行配置以启动宿主项目以及客户端。

要使客户端和服务器同时启动,您需要:

  • 右键单击您的解决方案文件,然后选择设置启动项目...
  • 选择多个启动项目并为您的客户端和服务器项目选择启动,将其他项目设置为无。
于 2012-02-08T20:20:33.507 回答