程序:
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(WcfServiceLib.Service1)))
{
if (host.State != CommunicationState.Opening)
host.Open();
Console.WriteLine("Host is runing! and state is {0}", host.State);
Console.Read();
}
}
错误信息 :
System.InvalidOperationException:“Service 'WcfServiceLib.Service1' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.”
解决办法:(直接到类库当中把配置文件拿过来用)
<system.serviceModel>
<diagnostics performanceCounters="Default" />
<services>
<service name="WcfServiceLib.Service1">
<endpoint address="" binding="basicHttpBinding" contract="WcfServiceLib.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/WcfServiceLib/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 为避免泄漏元数据信息,
请在部署前将以下值设置为 false -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<!-- 要接收故障异常详细信息以进行调试,
请将以下值设置为 true。在部署前设置为 false
以避免泄漏异常信息 -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
即可成功开启 服务:
http://localhost:8733/Design_Time_Addresses/WcfServiceLib/Service1/
本文解决了一个常见的WCF服务问题,即服务启动时报错‘Service'WcfServiceLib.Service1'haszeroapplication(non-infrastructure)endpoints’。通过在配置文件中正确设置服务、端点和地址等元素,成功启用了WCF服务。

1105

被折叠的 条评论
为什么被折叠?



