简体   繁体   English

WCF:同时使用流和用户名/密码身份验证

[英]WCF: Using Streaming and Username/Password authentication at the same time

I have a WCF Service with the following requirements: a) The client requests a file from the server which is transferred as a Stream. 我有一个具有以下要求的WCF服务:a)客户端从服务器请求文件,该文件作为流传输。 Files may be 100MB or larger. 文件可能大于或等于100MB。 I need streaming or chucking or whatever to make sure that IIS is not loading the whole package into memory before starting to send it. 我需要流式处理或卡住处理或其他任何操作以确保IIS在开始发送之前不会将整个程序包加载到内存中。 b) The client will transfer an ID to identify the file to be downloaded. b)客户端将传输一个ID,以标识要下载的文件。 The user should be authenticated by providing username/password. 用户应通过提供用户名/密码进行身份验证。 c) While the username/password part of the communication needs to be encrypted, encryption of the downloaded file is optional for our use case. c)虽然通信的用户名/密码部分需要加密,但对于我们的用例,下载文件的加密是可选的。

My other services, where I am returning smaller files, I am using the following binding: 我的其他服务(我要返回较小的文件)使用以下绑定:

<ws2007HttpBinding>
    <binding name="ws2007HttpExtern" maxReceivedMessageSize="65536000">
      <security mode="Message">
        <message clientCredentialType="UserName" />
      </security>
    </binding>        
  </ws2007HttpBinding>

But, as I said, that is no good for streaming (Message encryption needs the complete message to encrypt and that is not the case when streaming). 但是,正如我所说,这对流媒体没有好处(消息加密需要完整的消息进行加密,而流媒体则不是这种情况)。

So, I asked Microsoft support and I got more or less the following proposal: 因此,我请求Microsoft支持,或多或少获得了以下建议:

<bindings>
  <basicHttpBinding>
    <binding name="basicStreaming" 
      messageEncoding="Mtom" transferMode="StreamedResponse">
      <security mode="Transport">
        <transport clientCredentialType="Basic" />
      </security>
    </binding>
</bindings>

<services>
  <service behaviorConfiguration="MyProject.WCFInterface.DownloadBehavior"
    name="MyProject.WCFInterface.DownloadFile">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicStreaming"
      contract="MyProject.WCFInterface.IDownloadFile" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>    
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="MyProject.WCFInterface.DownloadBehavior">
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

When I use this, I get the following error message: 当我使用它时,出现以下错误信息:

Could not find a base address that matches scheme https for the endpoint with binding BasicHttpBinding. Registered base address schemes are [http].

I am using the Web Development Server so far (for production IIS7). 到目前为止,我正在使用Web开发服务器(用于生产IIS7)。

I have two questions. 我有两个问题。 a) How would you configure WCF to achieve the goal? a)您将如何配置WCF以实现目标? b) If the MS proposal is good: What I am doing wrong, the error message does not really help me. b)如果MS提案是好的:我做错了,错误消息并没有真正帮助我。

Thanks. 谢谢。

This error is usually related to hosting WCF services on IIS 7. WCF is not supported by default so here are some troubleshooting you can perform. 此错误通常与在IIS 7上托管WCF服务有关。默认情况下不支持WCF,因此,这里是一些可以执行的故障排除。

  1. Have you managed to host other WCF services on your IIS 7? 您是否已在IIS 7上托管了其他WCF服务? You may want to look into adding the WAS service feature on your IIS 7 server. 您可能需要研究在IIS 7服务器上添加WAS服务功能。 Here is a good tutorial. 是一个很好的教程。

  2. Https requires that you setup IIS with a proper SSL certificate and add a HTTPS binding to your site. Https要求您使用正确的SSL证书设置IIS,并将HTTPS绑定添加到您的站点。 Here is how. 是怎么回事。

As far a I know, the MS proposed solution works. 据我所知,MS建议的解决方案有效。 I used the same approach and it works fine. 我使用了相同的方法,并且效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM