【发布时间】:2014-06-10 20:21:53
【问题描述】:
您好,我正在制作控制台应用程序中托管的 wcf 是否可以使用 app.config 加载此服务?
ChannelFactory<IService> service = new ChannelFactory<IService>();
service.Endpoint.Behaviors.Add(new WebHttpBehavior());
IService channel = service.CreateChannel();
Console.Read();
这是我的 wcf 进入控制台应用程序的开始,但是如何加载 wcf 配置?
我是 wcf 的新手,所以请对我有礼貌。
--编辑--
所以我得到错误 s 零应用(非基础设施)端点。这可能是因为找不到您的应用程序的配置文件,或者因为在配置文件中找不到与服务名称匹配的服务元素,或者因为在服务元素中没有定义端点。
ServiceHost serviceHost = null;
serviceHost = new ServiceHost(typeof(Contracs.Service));
serviceHost.Open();
我的 app.config 是
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="restfulBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Contracs.Service">
<endpoint address="" behaviorConfiguration="restfulBehavior"
binding="webHttpBinding" bindingConfiguration="" contract="Contracs.IService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/Service" />
</baseAddresses>
</host>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
【问题讨论】:
-
Contracts.Service 是完整的命名空间吗?
-
命名空间合同这是命名空间我应该改变它吗?