我想创建WCF服务并通过Windows服务托管它。
我已经根据教程创建了所有内容https://msdn.microsoft.com/en-us/library/ff649818.aspx
这是我的WCF services library
App.config。我已将其更改为使用TCP协议
<system.serviceModel>
<services>
<service name="WCFServiceLibrary.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
contract="WCFServiceLibrary.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:3000/Service1" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
然后,我将App.config复制到WindowsService项目中。我还添加了WindowsService的安装程序,然后我更改了属性:
StartType - Automatic
Account - NetWorkService
然后我建立了这个项目使用Installutil WindowsService.exe
成功安装
但是,当我尝试添加服务时(net。tcp://localhost:3000/Service1)在我的WPFClientProject中的引用
它显示:
无法识别URI前缀。元数据包含一个引用无法解析:'net。tcp://localhost:3000/Service1"。无法连接到网络。tcp://localhost:3000/Service1.连接尝试持续时间为00:00:02.0614150。TCP错误代码10061:
我好像没有主持人。我做错了什么?
Windows服务代码
public partial class Service1: ServiceBase
{
internal static ServiceHost myServiceHost = null;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
if (myServiceHost != null)
{
myServiceHost.Close();
}
myServiceHost = new ServiceHost(typeof(Service1));
myServiceHost.Open();
}
protected override void OnStop()
{
if (myServiceHost != null)
{
myServiceHost.Close();
myServiceHost = null;
}
}
}
我在教程中遇到了与您相同的问题。
我通过验证windows服务是否正在运行来解决这个问题,因为登录凭据的原因,它没有运行。我将windows服务凭据更改为本地系统帐户,它就可以工作了。