无法添加服务客户端的WCF的net.tcp服务客户端、WCF、tcp、net

2023-09-04 01:22:33 作者:拿命搏未来

我想添加一个客户端是基于的net.tcp的WCF服务。当我使用添加服务引用,并提供该网址:的net.tcp://localhost/service1.svc ,它提供了以下错误

  

的URI preFIX无法识别。元数据包含一个引用   无法解析:'的net.tcp://localhost/service1.svc。不能   连接到的net.tcp://localhost/service1.svc。连接尝试   历时00一个时间跨度:00:02.0051147。 TCP错误code 10061:无   连接可以作出,因为目标机器积极地拒绝   它127.0.0.1:808。无连接可以作出,因为目标   计算机主动拒绝127.0.0.1:808如果该服务被定义   当前的解决方案,尝试建立溶液和添加服务   再次参考

我检查了Windows组件的WCF非HTTP服务,但他们都已经安装。这是捕捉:

正如你可以看到,他们安装的.NET 3.5.1和我的服务是建立在.NET 4.5。这是什么问题?而且我应该如何解决呢?因为在Windows组件列表中没有的选择.NET 4.5。

以下是我的WCF服务的配置:

 < system.serviceModel>
<服务>
<服务名称=CoreService.Service1behaviorConfiguration =BEH1>
  <主机>
    < baseAddresses>
      <新增baseAddress =的net.tcp://localhost/Service1.svc/>
    < / baseAddresses>
  < /主机>
        <端点
     绑定=NetTcpBinding的
     bindingConfiguration =超
     合同=CoreService.IAccountService/>
       <端点
     绑定=NetTcpBinding的
     bindingConfiguration =超
     合同=CoreService.ICategoryService/>
         <端点
     绑定=NetTcpBinding的
     bindingConfiguration =超
     合同=CoreService.ICommonService/>
         <端点
     绑定=NetTcpBinding的
     bindingConfiguration =超
     合同=CoreService.IFollowerService/>
         <端点
     绑定=NetTcpBinding的
     bindingConfiguration =超
     合同=CoreService.IInterestService/>
<端点
     绑定=NetTcpBinding的
     bindingConfiguration =超
     合同=CoreService.IInviteService/>

  <端点
          地址=MEX
          绑定=mexTcpBinding
          合同=IMetadataExchange接口/>
< /服务>
< /服务>
<绑定>
< NetTcpBinding的>
<绑定名称=超
     maxBufferPoolSize =2147483647
     maxBufferSize =2147483647
     MAXCONNECTIONS =2147483647
     maxReceivedMessageSize =2147483647
     portSharingEnabled =假
     transactionFlow =假
     将ListenBackLog =2147483647
     的SendTimeout =00:01:00>
<安全模式=无>
<消息clientCredentialType =无/>
<运输的ProtectionLevel =无clientCredentialType =无/>
< /安全>
<启用的ReliableSession =FALSE/>
< /装订>
< / NetTcpBinding的>
< /绑定>
<行为>
    < serviceBehaviors>
      <行为NAME =BEH1>
        < serviceMetadata httpGetEnabled =真/>
        < serviceDebug includeExceptionDetailInFaults =真/>
        < D​​ataContractSerializer的maxItemsInObjectGraph =65536/>
      < /行为>
    < / serviceBehaviors>
  < /行为>
< /system.serviceModel>
 

解决方案

这似乎不WCF的HTTP或者非HTTP激活功能和服务之间的不兼容问题。

据对我来说,有一个丢失或错误配置在IIS中,这会解释拒绝连接。要正确配置IIS与的net.tcp ,一看的这里。

I am trying to add a client for a WCF service that is net.tcp based. When I use "Add Service Reference" and provide this URL:net.tcp://localhost/service1.svc, it gives following error.

java 怎么调用.net wcf服务,怎么生成客户端代码

The URI prefix is not recognized. Metadata contains a reference that cannot be resolved: 'net.tcp://localhost/service1.svc'. Could not connect to net.tcp://localhost/service1.svc. The connection attempt lasted for a time span of 00:00:02.0051147. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:808. No connection could be made because the target machine actively refused it 127.0.0.1:808 If the service is defined in the current solution, try building the solution and adding the service reference again.

I checked Windows Components for WCF non-http services, but they are already installed. This is the snap:

As you can see they are installed for .NET 3.5.1 and my service is built in .NET 4.5. Is this the problem? And how should I solve it? Because there is no option for .NET 4.5 in Windows Components List.

Following is the configuration of my WCF service:

<system.serviceModel>
<services>
<service name="CoreService.Service1" behaviorConfiguration="beh1">
  <host>
    <baseAddresses>
      <add baseAddress="net.tcp://localhost/Service1.svc"/>
    </baseAddresses>
  </host>
        <endpoint
     binding="netTcpBinding"
     bindingConfiguration="ultra"
     contract="CoreService.IAccountService"/>
       <endpoint
     binding="netTcpBinding"
     bindingConfiguration="ultra"
     contract="CoreService.ICategoryService"/>
         <endpoint
     binding="netTcpBinding"
     bindingConfiguration="ultra"
     contract="CoreService.ICommonService"/>
         <endpoint
     binding="netTcpBinding"
     bindingConfiguration="ultra"
     contract="CoreService.IFollowerService"/>
         <endpoint
     binding="netTcpBinding"
     bindingConfiguration="ultra"
     contract="CoreService.IInterestService"/>
<endpoint
     binding="netTcpBinding"
     bindingConfiguration="ultra"
     contract="CoreService.IInviteService"/>

  <endpoint
          address="mex"
          binding="mexTcpBinding"
          contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="ultra"
     maxBufferPoolSize="2147483647"
     maxBufferSize="2147483647"
     maxConnections="2147483647"
     maxReceivedMessageSize="2147483647"
     portSharingEnabled="false"
     transactionFlow="false"
     listenBacklog="2147483647"
     sendTimeout="00:01:00">
<security mode="None">
<message clientCredentialType="None"/>
<transport protectionLevel="None" clientCredentialType="None"/>
</security>
<reliableSession enabled="false"/>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
    <serviceBehaviors>
      <behavior name="beh1">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="True" />
        <dataContractSerializer maxItemsInObjectGraph="65536" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

解决方案

It doesn't seem an incompatibility issue between the WCF HTTP or Non-HTTP Activation features and your service.

According to me, there's a missing or wrong configuration in IIS and that would explain the refused connection. To configure properly IIS with with net.tcp, have a look here.