实际上,我有两个不同的问题,这取决于我尝试运行看起来相关但以不同方式显示自己的服务的方式。请注意,我运行的代码是Microsofts guide中使用的代码的完全重复,但不同的名称空间和稍微不同的类名除外。WCF服务托管在Windows服务将无法正常运行
当我尝试使用此方法运行服务时,Windows服务成功启动,但是当它做到了WCF服务主机框会弹出,并且它提供了一条错误消息,表示IP端点localhost上已有一个侦听器。这里是我的配置文件,当我跑这样:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service behaviorConfiguration="CfmaWcfEphemerisLibrary.ServiceBehavior"
name="CfmaWcfEphemerisLibrary.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
contract="CfmaWcfEphemerisLibrary.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8529/Service1" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CfmaWcfEphemerisLibrary.ServiceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
一会儿战斗后,我发现了一个建议,说让TCP连接可能有助于在端口共享。我尝试过,但是当我尝试启动服务时失败,并在“应用程序”下的Windows事件日志中出现错误消息:
服务无法启动。 System.ServiceModel.AddressAlreadyInUseException:IP端点0.0.0.0:8529上已有一个侦听器。确保您没有试图在您的应用程序中多次使用此端点,并且没有其他应用程序正在侦听此端点。 ---> System.Net.Sockets.SocketException:通常只允许使用每个套接字地址(协议/网络地址/端口) 在System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot,SocketAddress套接字地址) System.Net.Sockets.Socket.Bind(EndPoint localEP) at System.ServiceModel.Channels.SocketConnectionListener.Listen() ---内部异常堆栈跟踪结束--- at System.ServiceModel.Channels.SocketConnectionListener.Listen () 在System.ServiceModel.Channels.BufferedConnectionListener.Listen() 在System.ServiceModel.Channels.ExclusiveTcpTransportManager.OnOpen() 在System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener) 在System.Service Model.Channels ....
我不明白为什么我在启用共享的端口上收到使用端口异常。当我尝试运行启用了端口共享的服务时,这是我的App.config文件。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service behaviorConfiguration="CfmaWcfEphemerisLibrary.ServiceBehavior"
name="CfmaWcfEphemerisLibrary.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpBinding"
contract="CfmaWcfEphemerisLibrary.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8529/Service1" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CfmaWcfEphemerisLibrary.ServiceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding portSharingEnabled="true" name="tcpBinding" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security>
<transport>
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
</security>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>
进入命令提示符。运行netstat -a。确保没有任何东西已经在使用端口8529.另外,如果您在代码中发布了如何在Windwos服务中创建和凝视WCF服务主机,可能会有所帮助。 – user957902 2011-12-15 15:17:42