我只花了4个小时谷歌搜索试图找到我无法消费(添加服务参考)WCF托管在Windows服务。我得到的错误是这个
无法识别URI前缀。 元数据包含无法解析的引用:' net.tcp:// localhost:8523 / Service1'。 无法连接到net.tcp:// localhost:8523 / Service1。连接尝试持续时间跨度为00:00:02.0158574。 TCP错误代码10061:无法建立连接,因为目标计算机主动拒绝它127.0.0.1:8523。 无法建立连接,因为目标计算机主动拒绝它127.0.0.1:8523 如果在当前解决方案中定义了服务,请尝试构建解决方案并再次添加服务引用。
我按照本教程https://msdn.microsoft.com/en-us/library/ff649818.aspx创建了一个小型服务。我被困在第8步,我在上面发布了错误。
我的App.config(WCF配置)
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<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>
<bindings />
<services>
<service name="WcfServiceLibrary1.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
name="netTcpEndpoint" contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="" binding="mexTcpBinding" bindingConfiguration=""
name="mexTCPendpoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8523/Service1" />
</baseAddresses>
<timeouts closeTimeout="00:01:00" openTimeout="00:02:00" />
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug httpHelpPageEnabled="false" httpsHelpPageEnabled="false"
includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Service.1.cs
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;
}
}
}
到目前为止我尝试过的事情:
我非常感谢任何有关我无法使用WCF的帮助。