WCF流传输:仅在net.tcp模式下出现框架错误

4
我有一个应用程序服务器,使用默认的transferMode="Buffered"实现一堆服务和一个Streamed服务。它公开了basicHttpnet.tcp协议的端点,并在数十个IIS 7.0+配置下运行生产环境,没有发生任何问题。
当我尝试为新的应用程序服务器复制这个架构时,通过net.tcp进行流传输就会拒绝工作,并抛出完全模糊和晦涩的ProtocolException

正在使用的.Net Framing模式不受支持。有关详细信息,请参见服务器日志。

是的,"服务器日志"。(无论是否跟踪都没有任何东西。) S1和S2的服务架构和web.config相同,除了:
  • 一些名称更改
  • S2中的自定义命名空间(S1使用tempuri)
  • 不同的端口(S1和S2都使用8000-9000范围内的端口)
使用basicHttp的流服务S2可以正常工作。
尝试了一切方法都未能解决错误后,我构建了一个测试客户端,仅使用一些 Ping 方法运行我的服务架构。没有自定义命名空间,没有花哨的东西,只有原始配置和轻量级的服务、契约以及手动编写的包装器,围绕 ChannelFactory 代理。
同样的错误:
“正在使用的 .Net Framing 模式不受 'net.tcp://localhost:9931/StreamingService.svc' 支持。有关更多详细信息,请参阅服务器日志。”
缓冲测试服务在两种协议下都可以工作,而流式服务在 basicHttp 下可以工作,就像 S2 中一样。
所有测试都在同一台安装有完整 IIS 的 Win7 计算机上进行。测试应用程序仍然太大,无法在此处发布,但这里提供了完整的配置和控制台代码。

web.config

<configuration>
  <connectionStrings>
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <!-- throttling of stream size is partially controlled by this setting -->
    <httpRuntime maxRequestLength="1048576" /><!-- 1GB -->
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment>
      <serviceActivations>
        <add relativeAddress="FooService.svc" service="WcfTest.Services.FooService" />
        <add relativeAddress="StreamingService.svc" service="WcfTest.Services.StreamingService" />
     </serviceActivations>
    </serviceHostingEnvironment>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <dataContractSerializer maxItemsInObjectGraph="200000" />
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding
                 openTimeout="00:20:00" sendTimeout="00:20:00" receiveTimeout="00:20:00" closeTimeout="00:20:00"
                 maxBufferSize="20000000" maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000">
          <readerQuotas maxStringContentLength="12000" />
        </binding>
        <binding name="WcfTest.Streaming.Http" transferMode="Streamed"
                 openTimeout="03:00:00" sendTimeout="03:00:00" receiveTimeout="03:00:00" closeTimeout="03:00:00"
                 maxReceivedMessageSize="1073741824" /><!-- 1GB -->
      </basicHttpBinding>
      <netTcpBinding>
        <binding
                 openTimeout="00:20:00" sendTimeout="00:20:00" receiveTimeout="00:20:00" closeTimeout="00:20:00"
                 maxBufferSize="20000000" maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000">
          <readerQuotas maxStringContentLength="12000" />
        </binding>
        <binding name="WcfTest.Streaming.Tcp" transferMode="Streamed"
                 openTimeout="03:00:00" sendTimeout="03:00:00" receiveTimeout="03:00:00" closeTimeout="03:00:00"
                 maxReceivedMessageSize="1073741824"><!-- 1GB -->
        </binding>
      </netTcpBinding>
    </bindings>
    <protocolMapping>
      <add scheme="http" binding="basicHttpBinding" />
      <add scheme="net.tcp" binding="netTcpBinding"/>
    </protocolMapping>
    <services>
      <service name="WcfTest.Services.Streaming">
        <!-- http -->
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="WcfTest.Streaming.Http" contract="WcfTest.Contracts.IStreamingService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <!-- net.tcp -->
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="WcfTest.Streaming.Tcp" contract="WcfTest.Contracts.IStreamingService" />
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

app.config

<configuration>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior>
          <dataContractSerializer maxItemsInObjectGraph="200000"/>
        </behavior>
        <behavior name="customQuotaBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding
                 openTimeout="00:20:00" sendTimeout="00:20:00" receiveTimeout="00:20:00" closeTimeout="00:20:00"
                 maxBufferSize="20000000" maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000">
          <readerQuotas maxStringContentLength="12000" />
        </binding>
        <binding name="WcfTest.Bindings.Streaming.Http" transferMode="Streamed"
                 openTimeout="03:00:00" sendTimeout="03:00:00" receiveTimeout="03:00:00" closeTimeout="03:00:00"
                 maxReceivedMessageSize="1073741824"><!-- 1GB -->
          </binding>
      </basicHttpBinding>

      <netTcpBinding>
        <binding
                 openTimeout="00:20:00" sendTimeout="00:20:00" receiveTimeout="00:20:00" closeTimeout="00:20:00"
                 maxBufferSize="20000000" maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000">
          <readerQuotas maxStringContentLength="12000" />
        </binding>
        <binding name="WcfTest.Bindings.Streaming.Tcp" transferMode="Streamed"
                 openTimeout="03:00:00" sendTimeout="03:00:00" receiveTimeout="03:00:00" closeTimeout="03:00:00"
                 maxReceivedMessageSize="1073741824"><!-- 1GB -->
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <!-- Foo -->
      <endpoint name="WcfTest.Endpoints.Foo.Http" address="http://localhost:9930/FooService.svc" binding="basicHttpBinding" contract="WcfTest.Contracts.IFooService" />
      <endpoint name="WcfTest.Endpoints.Foo.Tcp" address="net.tcp://localhost:9931/FooService.svc" binding="netTcpBinding" contract="WcfTest.Contracts.IFooService" />

      <!-- Streaming -->
      <endpoint name="WcfTest.Endpoints.Streaming.Http" address="http://localhost:9930/StreamingService.svc" binding="basicHttpBinding" bindingConfiguration="WcfTest.Bindings.Streaming.Http" contract="WcfTest.Contracts.IStreamingService" />
      <endpoint name="WcfTest.Endpoints.Streaming.Tcp" address="net.tcp://localhost:9931/StreamingService.svc" binding="netTcpBinding" bindingConfiguration="WcfTest.Bindings.Streaming.Tcp" contract="WcfTest.Contracts.IStreamingService" />
    </client>
  </system.serviceModel>
</configuration>

控制台测试调用

static void Main(string[] args)
        {
            Console.WriteLine("starting WcfTest client...");

            Console.WriteLine();
            PingFoo(Contracts.Enums.Protocol.Http);
            PingFoo(Contracts.Enums.Protocol.Tcp);

            Console.WriteLine();
            PingStreaming(Contracts.Enums.Protocol.Http);
            // only this call errors:
            PingStreaming(Contracts.Enums.Protocol.Tcp);

            Console.WriteLine();
            Console.Write("ENTER to exit WcfTest client...");
            Console.ReadLine();
        }

        private static bool PingFoo(Contracts.Enums.Protocol protocol)
        {
            FooProxy pxy = new FooProxy(protocol);
            return PingProxy<IFooService>(pxy, protocol);
        }

        private static bool PingStreaming(Contracts.Enums.Protocol protocol)
        {
            StreamingProxy pxy = new StreamingProxy(protocol);
            return PingProxy<IStreamingService>(pxy, protocol);
        }

        private static bool PingProxy<T>(ProxyServiceBase<T> pxy, Contracts.Enums.Protocol protocol) where T : IServiceBase
        {
            bool success = pxy.Ping(); 
            Console.WriteLine("ping {0} {1}: {2}", pxy.GetType().Name, protocol, success ? " success" : " FAILED");
            if (pxy != null)
                pxy.Close();
            return success;
        }

任何想法为什么这个在一个IIS站点上失败,在两种协议下的一个,而另一个没有?(它不是this。)
编辑:为了准备采取这个赏金方面,对这个测试服务和客户端的一些澄清:
首先,根据评论者的建议,svcutil针对http运行良好,但针对net.tcp失败。以下是该运行的完整输出:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin>svcutil net.tcp://localhost:9931/StreamingService.svc Microsoft (R) Service Model Metadata Tool [Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152] 版权所有(c) Microsoft Corporation。保留所有权利。
尝试使用WS-Metadata Exchange从'net.tcp://localhost:9931/StreamingService.svc'下载元数据。此URL不支持DISCO。Microsoft(R)服务模型元数据工具[Microsoft(R) Windows(R)通信基础结构,版本3.0.4506.2152] 版权所有(c) Microsoft Corporation。保留所有权利。
错误:无法从net.tcp://localhost:9931/StreamingService.svc获取元数据
如果这是您可以访问的Windows(R)通信基础结构服务,请检查您是否已在指定地址上启用元数据发布。有关启用元数据发布的帮助,请参阅MSDN文档http://go.microsoft.com/fwlink/?LinkId=65455
WS-Metadata Exchange错误 URI:net.tcp://localhost:9931/StreamingService.svc
元数据包含一个无法解析的引用:“net.tcp://localhost:9931/StreamingService.svc”。
套接字连接已中止。这可能是由于处理消息时发生错误或远程主机超时导致接收超时,或者是底层网络资源问题引起的。本地套接字超时为“00:04:59.9929993”。
现有连接已被远程主机强制关闭
如果您需要更多帮助,请键入“svcutil /?”
其次,从上面粘贴的Wcf.Bindings.Streaming.Tcp网络和应用程序配置中删除"transferMode="Streamed"可以使服务正常运行。但这并不能改善svcutil的情况。
最后,以下是我尝试过的其他方法,但都没有改善:
  • serviceBehaviorsserviceMetadata属性的各种版本(我理解这些被mex端点覆盖)
  • 使用各种命名的serviceBehaviors而不是我包含的默认值
  • 在绑定上使用各种security mode=配置,特别是None
  • 禁用所有其他绑定、端点等,希望其中一个东西可能会妨碍另一个东西

请放置 StreamingProxy 代码进行检查。 - Jones
@Jones 那个代理里面没有任何东西。通道开启和Ping调用发生在ProxyServiceBase中,正如我所说的那样,它与之前工作的服务完全相同。 - downwitch
使用 svcutil net.tcp://localhost:9931/StreamingService.svc 命令,并验证响应是否正确。如果不正确,使用 http://msdn.microsoft.com/en-us/library/ms730064(v=vs.100).aspx 中的日志来确定错误发生的确切位置。 - Jones
@Jones 很抱歉回复得这么慢... 我从 svcutil 得到了“元数据包含无法解析的引用”的响应。我在这方面进行了大量搜索,但我的元数据配置是正确的(而且重要的是,与之前/比较服务相同)。启用跟踪并且日志中没有错误。 - downwitch
1个回答

1

客户端(应用程序)和服务器(Web)配置文件在原始帖子中,均明确说明使用Streamed。我不知道“在TCP的情况下,在“StreamingProxy”中是否忘记了什么?”的意思,因为我没有在代码中设置我的协议。 - downwitch
我的意思是说,即使您在app.config中设置了binding.TransferMode = TransferMode.Streamed,您是否在ping方法的StreamingProxy类中也进行了设置?(正如Jones所述的那样)。 试图弄清楚如果wcf已正确配置,则应该是客户端使用缓冲模式,因为两个配置都看起来不错。 - Dharmendra Kumar Mistry

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接