【发布时间】:2015-05-30 16:05:53
【问题描述】:
我正在尝试创建自己的 WCF 服务和客户端。我使用以下 app.config 设置创建了我的服务:
<system.serviceModel>
<services>
<service name="Interface.MyWCFService">
<endpoint address="http://localhost:9999/MyService" binding="basicHttpBinding"
bindingConfiguration="" name="MyServiceEndpoint" contract="Interface.IMyWCFService" />
</service>
</services>
</system.serviceModel>
服务无异常启动。
我的客户应该连接到这个服务。他的 app.config 就是这个:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<endpoint address="http://localhost:9999/MyService" binding="basicHttpBinding"
bindingConfiguration="" contract="Interface.IMyWCFService"
name="MyServiceEndpoint" kind="" endpointConfiguration="" />
</client>
</system.serviceModel>
</configuration>
在 c# 代码中,我尝试使用以下代码在 client.cs 中创建一个通道工厂:
ChannelFactory<IMyWCFService> channelFactory = new ChannelFactory<IMyWCFService>("MyServiceEndpoint", new EndpointAddress("http://localhost:9999/MyService"));
IMyWCFService proxy = channelFactory.CreateChannel();
这不起作用。每次我尝试启动程序时,都会出现以下异常:
没有名称为“MyServiceEndpoint”和合同的 Endpointelement “Interface.IMyWCFService”位于 ServiceModel-Client 配置部分。
我希望你能帮助我。
【问题讨论】:
标签: c# wcf channelfactory