无法将服务引用添加到 net tcp wcf 服务 [英] Can't add service reference to net tcp wcf service

查看:32
本文介绍了无法将服务引用添加到 net tcp wcf 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WCF 服务作为 Windows 服务托管在我的本地机器上.现在我试图在客户端(再次在我的本地开发机器上)添加一个服务引用,但我收到一个错误

I have a WCF service hosted on my local machine as windows service. Now I'm trying to add a service reference in the client (again on my local dev machine) but I'm getting an error

元数据包含无法解析的引用:'net.tcp://localhost:8523/Service1'.无法连接到net.tcp://localhost:8523/Service1.连接尝试持续了时间跨度为 00:00:02.0011145.TCP 错误代码 10061:无连接可能是因为目标机器主动拒绝了

Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8523/Service1'. Could not connect to net.tcp://localhost:8523/Service1. The connection attempt lasted for a time span of 00:00:02.0011145. TCP error code 10061: No connection could be made because the target machine actively refused it

我检查了 Windows 防火墙没有阻止端口 8523.我什至在 Windows 防火墙中创建了一个新规则来允许运行 8523 端口.但是当我运行 netstat -sp tcp 时,我似乎找不到端口 8523.但是我可以看到 Serice1 服务的状态在服务中设置为 START.这是配置文件

I checked that the Windows firewall doesn't block port 8523. I even created a new rule in Windows firewall to allow run 8523 port. But when I'm running netstat -sp tcp I can't seem to find port 8523. But I can see Serice1 service's state is set to START in Services. This is the config files

服务库

<system.serviceModel>
  <services>
    <service name="WcfServiceLibrary1.Service1">
      <endpoint 
           address="" 
           binding="netTcpBinding" bindingConfiguration=""
           contract="WcfServiceLibrary1.IService1">
         <identity>
           <dns value="localhost" />
         </identity>
      </endpoint>
      <endpoint 
           address="mex" 
           binding="mexTcpBinding" bindingConfiguration=""
           contract="IMetadataExchange" />
      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost:8523/Service1" />
        </baseAddresses>
      </host>
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="">
        <serviceMetadata httpGetEnabled="false" />
        <serviceDebug includeExceptionDetailInFaults="false" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

windows 服务项目中的配置看起来相同.

Config in the windows service project looks identical.

推荐答案

Michael,这是我通常用于 WCF 服务的 net.tcp 绑定.

Michael, this is a net.tcp binding that I typically use for a WCF service.

    <bindings>
        <netTcpBinding>
            <binding name="TcpBinding"
                     receiveTimeout="Infinite"
                     sendTimeout="Infinite"
                     maxBufferSize="2147483647"
                     maxReceivedMessageSize="2147483647">
                <reliableSession inactivityTimeout="Infinite"/>
                <security mode="None"/>
            </binding>
        </netTcpBinding>
    </bindings>

尝试将其添加到您的配置中:

Try to add it to your configuration:

<service name="WcfServiceLibrary1.Service1">   
    <endpoint    
        address=""    
        binding="netTcpBinding" bindingConfiguration="TcpBinding"   
        contract="WcfServiceLibrary1.IService1">   
    ...

此外,我的服务在 ServiceAccount.LocalSystem 下运行.

Also, my services are running under ServiceAccount.LocalSystem.

检查

netstat -ap tcp

netstat -ap tcp

如果服务正在监听.

下面是我的服务类.请注意,windows 服务的当前目录以编程方式设置为 BaseDirectory,即可执行文件的目录.

my Service class below. Note that the current directory of the windows service is set programatically to the BaseDirectory, i.e. the directory of the executable.

public class Service : ServiceBase
{
    public static void Main()
    {
        Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
        ServiceBase.Run(new Service());
    }

    ...
}

这篇关于无法将服务引用添加到 net tcp wcf 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆