可扩展的 WCF 解决方案
我正在尝试实现可扩展的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
服务主机的配置是什么?听起来像是两个问题之一:
我想通过检查服务主机项目的 web.config,您可能会发现它要么在不同的端口上侦听,要么根本没有运行,因此没有侦听。
Visual Studio 主机是否正在启动并托管该服务?您通常会在时钟旁边的通知区域中看到一个小“吐司”弹出窗口,表示主机正在运行,您可以看到它正在哪个端口上运行。如果这种情况没有发生,那么您可能需要对其进行配置以启动宿主项目和客户端。
要使客户端和服务器能够同时启动,您需要:
what is the config of the service host? sounds like one of 2 problems:
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: