可扩展的 WCF 解决方案

发布于 2025-01-03 09:17:12 字数 1921 浏览 1 评论 0原文

我正在尝试实现可扩展的 wcf 解决方案,位于 NetFX Harmonics:创建精简、简化且可扩展的 WCF 连接

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

  • Contact.Service(服务和数据契约)
  • Contact.ServiceImpl(HostFactory 和 Service 本身)
  • Contact.ServiceHost(Web.config 和 Person.svc)
  • Contact.ServiceClient

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

App.config

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

Program.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" %>

I am trying to implement scalable wcf solution found at NetFX Harmonics: Creating Streamlined, Simplified, yet Scalable WCF Connectivity

So my solution have 4 projects

  • Contact.Service (Service and Data Contracts)
  • Contact.ServiceImpl (HostFactory and Service itself)
  • Contact.ServiceHost (Web.config and Person.svc)
  • Contact.ServiceClient

Contact.ServiceClient have App.config and Program.cs which actually call service.

App.config

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

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

When I try running this example exception is thrown:

There was no endpoint listening at http://localhost:1031/Person.svc that could accept the message. This is often caused by an incorrect address or SOAP action.

P.S. Person.svc is in my Contact.ServiceHost project

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

当梦初醒 2025-01-10 09:17:12

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

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

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

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

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

  • 右键单击​​解决方案文件,然后选择设置启动项目...
  • 选择多个启动项目,然后为客户端和服务器项目选择启动,保留其他项目那些设置为无。

what is the config of the service host? sounds like one of 2 problems:

  • the service host is not set up to listen on the same port.
  • the host application is not being run at all

I imagine that by checking the web.config of the service host project you'll likely find that it is either listening on a different port, or not being run at all, and hence not listening.

Is the Visual studio host starting up and hosting the service? You usually get a little 'toast' pop up window in the notification area next to the clock saying the the host is running and you can see which port it is running on. if this is not happening then it is likely that you need to configure it to start the host project as well as the client.

To enable both the client and server to start at the same time you need to:

  • Right-click on your solution file, and choose Set Startup Projects...
  • Choose Multiple startup projects and choose Start for your client and server project, leave the other ones set to none.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文