【问题标题】:WCF NetTcp Configuration IssueWCF NetTcp 配置问题
【发布时间】:2013-07-24 00:54:39
【问题描述】:

我们在为我们在 IIS 中本地托管的 WCF WebService 配置 netTcp 时遇到问题。这是在带有 DotNet 4.0 (VS2012) 的 Windows 7 和 IIS 7 上,防火墙被禁用。

我们已经完成了以下步骤来配置netTcp:

  1. 在 IIS 中,为 net.tcp 808 设置站点绑定:* 为默认网站
  2. 在我们的 Web 服务的 IIS 中,启用的协议是“http,net.tcp”(无空格)
  3. 已验证 Net.Tcp 侦听器适配器和 Net.Tcp 端口共享服务正在运行(也回收了它们)

现在,当我们运行 netstat -ona 时,我们看不到 127.0.0.1:808 的任何列表 - 我们应该吗???

这是我的 Web.config:

<system.web>
<customErrors mode="Off"></customErrors>
<compilation debug="true" targetFramework="4.0"></compilation>
    <identity impersonate="false" />
</system.web> 
<system.serviceModel>
<diagnostics>
  <messageLogging logMalformedMessages="false" logMessagesAtServiceLevel="false"
    logMessagesAtTransportLevel="false" />
</diagnostics>
<bindings>
  <netTcpBinding>
    <binding name="XxxxxxxCommonServiceBinding"  />
  </netTcpBinding>
</bindings>
<services>
  <service behaviorConfiguration="XxxxxxxCommonService_Behavior" name="CS.WebService.Xxxxxxx.Common.XxxxxxxCommonService">
    <endpoint address="net.tcp://localhost:808/CS.WebService.Xxxxxxx.Common.XxxxxxxCommonService/XxxxxxxCommonService.svc" binding="netTcpBinding"
              bindingConfiguration="XxxxxxxCommonServiceBinding" name="XxxxxxxCommonNetTcpBinding"
              contract="CS.ServiceContracts.Xxxxxxx.Common.IXxxxxxxCommonService" />
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />      
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="XxxxxxxCommonService_Behavior">
      <serviceMetadata httpGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="false" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false">      
 </serviceHostingEnvironment>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>

这里是 App.config:

<system.serviceModel>
<client>
  <endpoint name="CS.WebService.Xxxxxxx.Common.XxxxxxxCommonService"
            address="net.tcp://localhost/CS.WebService.Xxxxxxx.Common.XxxxxxxCommonService/XxxxxxxCommonService.svc"
            binding="netTcpBinding"
            bindingConfiguration="XxxxxxxCommonNetTcpBinding"
            contract="CS.ServiceContracts.Xxxxxxx.Common.IXxxxxxxCommonService"/>
</client>    
</system.serviceModel>

这是我尝试调用服务的客户端中的代码:

var endPoint = new EndpointAddress(
            "net.tcp://127.0.0.1:809/CS.WebService.Xxxxxx.Common.XxxxxxCommonService/XxxxxxCommonService.svc");
var binding = new NetTcpBinding { TransferMode = TransferMode.Streamed, SendTimeout = TimeSpan.MaxValue };
var channel = new ChannelFactory<IXxxxxxCommonService>(binding, endPoint);
var proxy = channel.CreateChannel()
var request = new GetDataRequest();
var response = proxy.GetData(request);

此时我们得到以下错误:

无法连接到 net.tcp://127.0.0.1:809/CS.WebService.Xxxxxx.Common.XxxxxxCommonService/XxxxxxCommonService.svc。连接尝试持续了 00:00:00 的时间跨度。 TCP错误代码10061:无法建立连接,因为目标机器主动拒绝它127.0.0.1:809。

如果我将代码和 WebConfig 中的端口更改为 808,我们会收到以下错误:

在 net.tcp://127.0.0.1/CS.WebService.Xxxxxx.Common.XxxxxxCommonService/XxxxxxCommonService.svc 上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。有关更多详细信息,请参阅 InnerException(如果存在)。 (注意,没有内部异常)

所以在我看来,因为 netstat -ona 没有显示 127.0.0.1:808 我没有正确配置某些东西。但是 Net.Tcp 服务再次运行并已被回收,我相信 IIS 设置也正确,所以不知道该转向哪里。

【问题讨论】:

  • 您似乎配置了 WCF 跟踪。我会确保客户端和服务都启用了跟踪并从客户端跟踪文件开始,看看哪里抛出了异常。另外,尝试让a simple netHttpBinding sample 运行并将工作配置与您的配置进行比较。

标签: c# wcf


【解决方案1】:

转到控制面板 > 程序和功能 > 打开或关闭 Windows 功能。 在随后的对话框中,转到条目Microsoft .NET Framework 3.5.1 并启用Windows Communication Foundation Non-HTTP Activation。 (虽然上面写着 3.5.1 - Win7 内置在框架中 - 它也适用于 4.0)。

您应该在 netstat 输出中看到 0.0.0.0:808

【讨论】:

  • 我的客户端代码中有一个端点地址类型。我解决了这个问题,现在我正在做一个不同的错误。我这样做了 0.0.0.0:808 所以看起来没问题。
  • 我现在的错误是 Contract 不允许 Session,但是 Binding 'NetTcpBinding' 不支持 Datagram 。所以我更改了channel.Endpoint.Contract.SessionMode = SessionMode.Allowed,但仍然得到同样的错误。
  • @77vetter:如果你想改变SessionMode,它应该在客户端和服务器上都改变。但是,我不确定这会解决您的问题。如果您无法修复它,您应该发布新问题来描述您的新问题。
  • 一旦我将客户端和服务器上的 SessionMode 更改为允许一切开始工作。
【解决方案2】:

更改了 SessionMode.Allowed 在客户端和服务器上,一切都开始工作了。我的电脑上也有内存问题,所以一旦我清除了内存并正确设置了 sessionMode,一切都很好。开启追踪功能为我指明了正确的方向。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-02
    • 2012-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-04
    相关资源
    最近更新 更多