我正在尝试实现在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" %>