双工模式StreamedRequest无法使用可靠的会话绑定

时间:2009-12-09 20:03:01

标签: c# wcf streaming nettcpbinding

我一直在努力解决这个问题,并且可以真正使用一些帮助。

我正在尝试设计一个WCF端点,允许将图像流式传输到服务器,然后返回imageURL(即:“http://images.site.com/someimage.jpg”)。

目前,对我的WCF方法的调用如下所示:

for (var i = 0; i <= (Request.Files.Count - 1); i++)
{
client = new SOAPFileTransferServiceClient();
fileinfo = new FileTransferInfo();
m_objFile = Request.Files[i];

if (!(m_objFile == null | string.IsNullOrEmpty(m_objFile.FileName) |  _objFile.ContentLength < 1))
   {

   fileinfo.FileSize = m_objFile.ContentLength;
   fileinfo.FileName = Path.GetFileName(m_objFile.FileName);
   fileinfo.UserID = Context.Request["sid"].ToString();

   client.UploadFile(fileinfo, m_objFile.InputStream);

   if (retParam.param2 == 0)
   imgurl.Add(retParam.param1);

  }

}

我正在努力解决的错误是:

  

传输模式流式传输不是   支持   ReliableSessionBindingElement。

到目前为止,我已尝试使用创建自定义netTcp绑定 在消息编码元素之前添加。我也改变了我的transerMode属性 到streamedRequest(感谢marc_s的建议)允许请求流式传输而不是响应。这似乎可以做到这一点,但我仍然得到相同的错误(这次“传输模式StreamedRequest不是......”)。

我没有想法。

以下是文件传输服务合同。除了SOAP端点之外,我还有JSON和POX。我还有两个MEX端点(一个用于mexHttp,另一个用于netTcp)。最后,我有http(对于json和pox)和netTcp(对于soap)基地址。

有什么不对劲吗?

<service behaviorConfiguration="transferServiceBehavior" name="MyProject.API.FileTransfer.FileTransferService">
            <endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
              binding="webHttpBinding" bindingConfiguration="jsonWeb" name="MyJSONFileTransferEP"
              contract="MyProject.API.FileTransfer.IJSONFileTransferService" />
            <endpoint address="pox" behaviorConfiguration="WebHttpEPBehavior"
              binding="webHttpBinding" bindingConfiguration="poxWeb" name="MyPOXFileTransferEP"
              contract="MyProject.API.FileTransfer.IPOXFileTransferService" />
            <endpoint address="httpMex" binding="mexHttpBinding" bindingConfiguration=""
              contract="IMetadataExchange" />
            <endpoint address="soap" behaviorConfiguration="NetTcpEPBehavior"
              binding="customBinding" bindingConfiguration="netTcpCustom"
              name="MySOAPFileTransferEP" contract="MyProject.API.FileTransfer.ISOAPFileTransferService" />
            <endpoint address="nettcpMex" binding="netTcpBinding" bindingConfiguration=""
              contract="IMetadataExchange" />
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:2544/filetransfer/" />
                <add baseAddress="net.tcp://localhost:2544/filetransfer/" />
              </baseAddresses>
            </host>
          </service>

这是我的服务合同使用的自定义绑定:

<customBinding>
    <binding name="netTcpCustom"
             closeTimeout="00:01:00"
             openTimeout="00:01:00"
             receiveTimeout="00:10:00"
             sendTimeout="00:01:00">
      <reliableSession />
      <compositeDuplex />
      <oneWay />
      <windowsStreamSecurity protectionLevel="None" />
      <mtomMessageEncoding  />
      <tcpTransport maxBufferPoolSize="524288"
                    maxReceivedMessageSize="2147483647"
                    connectionBufferSize="8192"
                    hostNameComparisonMode="StrongWildcard"
                    channelInitializationTimeout="00:01:00"
                    maxBufferSize="2147483647"
                    maxPendingConnections="20"
                    maxOutputDelay="00:00:00.2000000"
                    maxPendingAccepts="5"
                    transferMode="StreamedRequest"
                    listenBacklog="20"
                    portSharingEnabled="false"
                    teredoEnabled="false">
        <connectionPoolSettings groupName="default" leaseTimeout="00:05:00"
            idleTimeout="00:02:00" maxOutboundConnectionsPerEndpoint="20" />
      </tcpTransport>
    </binding>
  </customBinding>

最后,对于它的价值,下面是我在App.config中的整个system.serviceModel定义:

<system.serviceModel>
    <client>
      <endpoint address="http://localhost:2542/auth/json" behaviorConfiguration="WebHttpEPBehavior"
        binding="webHttpBinding" bindingConfiguration="jsonWeb" contract="Trezoro.WebAPI.Authentication.IJSONAuthService"
        name="MyJSONAuthEP">
        <identity>
          <certificateReference storeName="My" storeLocation="LocalMachine"
            x509FindType="FindBySubjectDistinguishedName" />
        </identity>
      </endpoint>
      <endpoint address="http://localhost:2542/auth/pox" behaviorConfiguration="WebHttpEPBehavior"
        binding="webHttpBinding" bindingConfiguration="poxWeb" contract="Trezoro.WebAPI.Authentication.IPOXAuthService"
        name="MyPOXAuthEP">
        <identity>
          <certificateReference storeName="My" storeLocation="LocalMachine"
            x509FindType="FindBySubjectDistinguishedName" />
        </identity>
      </endpoint>
      <endpoint address="http://localhost:2542/auth/soap" behaviorConfiguration="BasicHttpEPBehavior"
        binding="basicHttpBinding" bindingConfiguration="soapWeb" contract="Trezoro.WebAPI.Authentication.ISOAPAuthService"
        name="MySOAPAuthEP">
        <identity>
          <certificateReference storeName="My" storeLocation="LocalMachine"
            x509FindType="FindBySubjectDistinguishedName" />
        </identity>
      </endpoint>
      <endpoint address="http://localhost:2542/auth/mex" binding="mexHttpBinding"
        bindingConfiguration="" contract="IMetadataExchange" name="authmex">
        <identity>
          <certificateReference storeName="My" storeLocation="LocalMachine"
            x509FindType="FindBySubjectDistinguishedName" />
        </identity>
      </endpoint>
      <endpoint address="http://localhost:2543/trade/json" behaviorConfiguration="WebHttpEPBehavior"
        binding="webHttpBinding" bindingConfiguration="jsonWeb" contract="Trezoro.WebAPI.Trade.IJSONTradeService"
        name="MyJSONTradeEP">
        <identity>
          <certificateReference storeName="My" storeLocation="LocalMachine"
            x509FindType="FindBySubjectDistinguishedName" />
        </identity>
      </endpoint>
      <endpoint address="http://localhost:2543/trade/pox" behaviorConfiguration="WebHttpEPBehavior"
        binding="webHttpBinding" bindingConfiguration="poxWeb" contract="Trezoro.WebAPI.Trade.IPOXTradeService"
        name="MyPOXTradeEP">
        <identity>
          <certificateReference storeName="My" storeLocation="LocalMachine"
            x509FindType="FindBySubjectDistinguishedName" />
        </identity>
      </endpoint>
      <endpoint address="http://localhost:2543/trade/soap" behaviorConfiguration="BasicHttpEPBehavior"
        binding="basicHttpBinding" bindingConfiguration="soapWeb" contract="Trezoro.WebAPI.Trade.ISOAPTradeService"
        name="MySOAPTradeEP">
        <identity>
          <certificateReference storeName="My" storeLocation="LocalMachine"
            x509FindType="FindBySubjectDistinguishedName" />
        </identity>
      </endpoint>
      <endpoint address="http://localhost:2543/trade/mex" binding="mexHttpBinding"
        bindingConfiguration="" contract="IMetadataExchange" name="trademex">
        <identity>
          <certificateReference storeName="My" storeLocation="LocalMachine"
            x509FindType="FindBySubjectDistinguishedName" />
        </identity>
      </endpoint>
      <endpoint address="http://localhost:2544/filetransfer/json" behaviorConfiguration="WebHttpEPBehavior"
        binding="webHttpBinding" bindingConfiguration="jsonWeb" contract="Trezoro.WebAPI.FileTransfer.IJSONFileTransferService"
        name="MyJSONFileTransferEP">
        <identity>
          <certificateReference storeName="My" storeLocation="LocalMachine"
            x509FindType="FindBySubjectDistinguishedName" />
        </identity>
      </endpoint>
      <endpoint address="http://localhost:2544/filetransfer/pox" behaviorConfiguration="WebHttpEPBehavior"
        binding="webHttpBinding" bindingConfiguration="poxWeb" contract="Trezoro.WebAPI.FileTransfer.IPOXFileTransferService"
        name="MyPOXFileTransferEP">
        <identity>
          <certificateReference storeName="My" storeLocation="LocalMachine"
            x509FindType="FindBySubjectDistinguishedName" />
        </identity>
      </endpoint>
      <endpoint address="http://localhost:2545/filetransfer/soap" behaviorConfiguration="NetTcpEPBehavior"
        binding="customBinding" bindingConfiguration="netTcpCustom"
        contract="Trezoro.WebAPI.FileTransfer.ISOAPFileTransferService"
        name="MySOAPFileTransferEP">
        <identity>
          <certificateReference storeName="My" storeLocation="LocalMachine"
            x509FindType="FindBySubjectDistinguishedName" />
        </identity>
      </endpoint>
      <endpoint address="net.tcp://localhost:2545/filetransfer/nettcpMex"
        binding="netTcpBinding" bindingConfiguration="" contract="IMetadataExchange"
        name="filetransfermex">
        <identity>
          <certificateReference storeName="My" storeLocation="LocalMachine"
            x509FindType="FindBySubjectDistinguishedName" />
        </identity>
      </endpoint>
    </client>
    <bindings>
      <basicHttpBinding>
        <binding name="soapWeb" />
        <binding name="httpLargeMessageStream"
                 closeTimeout="00:01:00"
                 openTimeout="00:01:00"
                 receiveTimeout="00:10:00"
                 sendTimeout="00:01:00"
                 allowCookies="false"
                 bypassProxyOnLocal="false"
                 hostNameComparisonMode="StrongWildcard"
                 maxBufferSize="2147483647"
                 maxBufferPoolSize="2147483647"
                 maxReceivedMessageSize="2147483647"
                 messageEncoding="Text"
                 textEncoding="utf-8"
                 transferMode="StreamedRequest"
                 useDefaultWebProxy="true">
          <readerQuotas maxDepth="32"
                        maxStringContentLength="8192"
                        maxArrayLength="16384"
                        maxBytesPerRead="4096"
                        maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None"
                       proxyCredentialType="None"
                       realm="" />
            <message clientCredentialType="UserName"
                     algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
      <customBinding>
        <binding name="netTcpCustom"
                 closeTimeout="00:01:00"
                 openTimeout="00:01:00"
                 receiveTimeout="00:10:00"
                 sendTimeout="00:01:00">
          <reliableSession />
          <compositeDuplex />
          <oneWay />
          <windowsStreamSecurity protectionLevel="None" />
          <mtomMessageEncoding  />
          <tcpTransport maxBufferPoolSize="524288"
                        maxReceivedMessageSize="2147483647"
                        connectionBufferSize="8192"
                        hostNameComparisonMode="StrongWildcard"
                        channelInitializationTimeout="00:01:00"
                        maxBufferSize="2147483647"
                        maxPendingConnections="20"
                        maxOutputDelay="00:00:00.2000000"
                        maxPendingAccepts="5"
                        transferMode="StreamedRequest"
                        listenBacklog="20"
                        portSharingEnabled="false"
                        teredoEnabled="false">
            <connectionPoolSettings groupName="default" leaseTimeout="00:05:00"
                idleTimeout="00:02:00" maxOutboundConnectionsPerEndpoint="20" />
          </tcpTransport>
        </binding>
      </customBinding>
      <netTcpBinding>
        <binding name="netTcpWeb"
                 hostNameComparisonMode="StrongWildcard"
                 closeTimeout="00:01:00"
                 openTimeout="00:01:00"
                 receiveTimeout="00:10:00"
                 sendTimeout="00:01:00"
                 maxReceivedMessageSize="2147483647"
                 transferMode="StreamedRequest"
                 portSharingEnabled="false">
          <security mode="None" />
        </binding>
      </netTcpBinding>
      <webHttpBinding>
        <binding name="poxWeb"
                 maxBufferSize="1500000"
                 maxBufferPoolSize="1500000"
                 maxReceivedMessageSize="1500000">
          <readerQuotas maxDepth="32"
                        maxStringContentLength="656000"
                        maxArrayLength="656000"
                        maxBytesPerRead="656000"
                        maxNameTableCharCount="656000" />
        </binding>
        <binding name="jsonWeb"
                 maxBufferSize="1500000"
                 maxBufferPoolSize="1500000"
                 maxReceivedMessageSize="1500000">
          <readerQuotas maxDepth="32"
                        maxStringContentLength="656000"
                        maxArrayLength="656000"
                        maxBytesPerRead="656000"
                        maxNameTableCharCount="656000" />
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="Default" name="Trezoro.WebAPI.Authentication.AuthService">
        <endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
          binding="webHttpBinding" bindingConfiguration="jsonWeb" name="MyJSONAuthEP"
          contract="Trezoro.WebAPI.Authentication.IJSONAuthService" />
        <endpoint address="pox" behaviorConfiguration="WebHttpEPBehavior"
          binding="webHttpBinding" bindingConfiguration="poxWeb" name="MyPOXAuthEP"
          contract="Trezoro.WebAPI.Authentication.IPOXAuthService" />
        <endpoint address="soap" behaviorConfiguration="BasicHttpEPBehavior"
          binding="basicHttpBinding" bindingConfiguration="soapWeb" name="MySOAPAuthEP"
          contract="Trezoro.WebAPI.Authentication.ISOAPAuthService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:2542/auth/" />
          </baseAddresses>
        </host>
      </service>
      <service behaviorConfiguration="Default" name="Trezoro.WebAPI.Trade.TradeService">
        <endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
          binding="webHttpBinding" bindingConfiguration="jsonWeb" name="MyJSONTradeEP"
          contract="Trezoro.WebAPI.Trade.IJSONTradeService" />
        <endpoint address="pox" behaviorConfiguration="WebHttpEPBehavior"
          binding="webHttpBinding" bindingConfiguration="poxWeb" name="MyPOXTradeEP"
          contract="Trezoro.WebAPI.Trade.IPOXTradeService" />
        <endpoint address="soap" behaviorConfiguration="BasicHttpEPBehavior"
          binding="basicHttpBinding" bindingConfiguration="soapWeb" name="MySOAPTradeEP"
          contract="Trezoro.WebAPI.Trade.ISOAPTradeService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:2543/trade/" />
          </baseAddresses>
        </host>
      </service>
      <service behaviorConfiguration="transferServiceBehavior" name="Trezoro.WebAPI.FileTransfer.FileTransferService">
        <endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
          binding="webHttpBinding" bindingConfiguration="jsonWeb" name="MyJSONFileTransferEP"
          contract="Trezoro.WebAPI.FileTransfer.IJSONFileTransferService" />
        <endpoint address="pox" behaviorConfiguration="WebHttpEPBehavior"
          binding="webHttpBinding" bindingConfiguration="poxWeb" name="MyPOXFileTransferEP"
          contract="Trezoro.WebAPI.FileTransfer.IPOXFileTransferService" />
        <endpoint address="httpMex" binding="mexHttpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />
        <endpoint address="soap" behaviorConfiguration="NetTcpEPBehavior"
          binding="customBinding" bindingConfiguration="netTcpCustom"
          name="MySOAPFileTransferEP" contract="Trezoro.WebAPI.FileTransfer.ISOAPFileTransferService" />
        <endpoint address="nettcpMex" binding="netTcpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:2544/filetransfer/" />
            <add baseAddress="net.tcp://localhost:2544/filetransfer/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="WebHttpEPBehavior">
          <webHttp />
        </behavior>
        <behavior name="BasicHttpEPBehavior" />
        <behavior name="NetTcpEPBehavior" />
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="Default">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
        <behavior name="transferServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

任何和所有建议都非常感谢。谢谢你的帮助。

1 个答案:

答案 0 :(得分:1)

那么,如果丢弃可靠的会话元素,StreamedRequest方法是否有效?你能活下去吗?如果您使用的是netTcp,那么您可能会支持企业防火墙,对吗?所以你可能会在没有可靠的会话开销的情况下离开......

此外 - WCF有很多选项和可能的功能组合 - 并非一切都有意义,并不是所有东西都能协同工作 - 也许这只是WCF的一个限制,而不是你的配置问题。

你的配置唯一奇怪的是你的netTcp自定义绑定中的mtomMessageEncoding - 为什么不使用更有效的二进制编码?

<binding name="netTcpCustom"
         closeTimeout="00:01:00"
         openTimeout="00:01:00"
         receiveTimeout="00:10:00"
         sendTimeout="00:01:00">
  <reliableSession />
  <compositeDuplex />
  <oneWay />
  <windowsStreamSecurity protectionLevel="None" />
  <mtomMessageEncoding  />
  <tcpTransport maxBufferPoolSize="524288"

为什么不使用

  <binaryMessageEncoding /> 

代替??