在webHttp WCF服务上设置传输级别安全性

时间:2009-07-27 19:48:44

标签: wcf security webhttp

我正在尝试在webHttp绑定WCF服务上设置传输级安全性,我的当前配置看起来像这样

 <system.serviceModel>
<client>
  <endpoint binding="webHttpBinding" bindingConfiguration="webHttp"
    contract="PrimeStreamInfoServices.IService1" name="Client" />
</client>
<bindings>
<webHttpBinding>
  <binding name="webHttp" maxBufferPoolSize="1500000"  maxReceivedMessageSize="1500000"  maxBufferSize="1500000">
  <security mode="Transport">
      <transport clientCredentialType="None"

            proxyCredentialType="None"
            realm="string" />
  </security>
  </binding>

</webHttpBinding>
</bindings>
<services>

  <service name="PrimeStreamInfoServices.Service1" behaviorConfiguration="PrimeStreamInfoServices.Service1Behavior">
    <!-- Service Endpoints -->
    <endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttp" contract="PrimeStreamInfoServices.IService1">
      <!-- 
          Upon deployment, the following identity element should be removed or replaced to reflect the 
          identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
          automatically.
      -->
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="PrimeStreamInfoServices.Service1Behavior">

      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<diagnostics>

  <messageLogging logMalformedMessages="true"  logMessagesAtServiceLevel="true"
    logMessagesAtTransportLevel="true" />

</diagnostics>

然而,当我运行我的服务时,我得到一个例外: 找不到与绑定WebHttpBinding的端点的方案https匹配的基址。注册的基地址方案是[http]。

我知道我错过了一些东西,我一直在尝试各种各样的事情,我无法弄明白,任何人都对我必须做的事情有所了解?

4 个答案:

答案 0 :(得分:0)

是 - 使用合适的证书切换到HTTPS。在HTTP的情况下,传输安全性由SSL通道提供。您不能通过普通HTTPS

获得WS *传输安全性

答案 1 :(得分:0)

忽略我以前的回答,我在想wsHttpBinding而不是webHttpBinding。

这是您用来调用必须以https开头的服务的地址。

https://machineName/ServiceName

答案 2 :(得分:0)

您可以尝试添加基本地址(在服务配置的<host>元素内),这是https吗?您是否在代码中添加(或多个)基地址?

<service name="PrimeStreamInfoServices.Service1" 
         behaviorConfiguration="PrimeStreamInfoServices.Service1Behavior">
   <host>
      <baseAddresses>
         <add baseAddress="https://localhost:8080/YourService.svc" />
      </baseAddresses>
   </host>
   <!-- Service Endpoints -->
   <endpoint ......
</service>

不是100%确定是否适用于webHttpBinding,但试一试!

马克

答案 3 :(得分:0)

请记住,除了正确的WCF配置之外,您还需要配置IIS属性以在其上启用SSL(包括为SSL设置正确的X.509证书)。 docs有一些关于如何做的正确信息。