【问题标题】:REST WCF Service Over SSL基于 SSL 的 REST WCF 服务
【发布时间】:2011-01-10 20:57:07
【问题描述】:

我正在尝试通过 SSL 配置 REST WCF 服务,但我不断收到:

找不到一个基地址 匹配端点的方案 https 与绑定 WebHttpBinding。 注册的基地址方案是 [http]。

有人可以看看我的配置文件吗?谢谢。

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBinding1">
          <security>
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
       <mexHttpsBinding>
         <binding name="mexHttpsBinding1"/>
      </mexHttpsBinding>
      <webHttpBinding>
        <binding name="webHttpBinding1">
          <security mode="Transport" />
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="serviceBehavior" name="CompanyX.WebServices.WebApi">
        <endpoint address="" behaviorConfiguration="WebApiBehavior" binding="webHttpBinding"
          bindingConfiguration="webHttpBinding1" contract="CompanyX.WebServices.IWebApi">
          <identity>
           <certificateReference x509FindType="FindBySubjectName" findValue="CompanyXDev"
              isChainIncluded="false" storeName="My" storeLocation="LocalMachine" />
          </identity>
        </endpoint>
        <endpoint binding="mexHttpsBinding" bindingConfiguration="mexHttpsBinding1"
          name="mex" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="WebApiBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="serviceBehavior">
          <serviceMetadata httpsGetEnabled="true" httpGetBinding="" httpsGetBinding="webHttpBinding"
            httpsGetBindingConfiguration="webHttpBinding1" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceCredentials>
            <clientCertificate>
              <certificate findValue="CompanyXDev" x509FindType="FindBySubjectName" />
            </clientCertificate>
            <serviceCertificate findValue="CompanyXDev" x509FindType="FindBySubjectName" />
            <userNameAuthentication userNamePasswordValidationMode="Custom"
              customUserNamePasswordValidatorType="CompanyX.WebServices.CredentialsValidator, CompanyX.WebServices" />
            <peer>
              <certificate findValue="CompanyXDev" storeLocation="LocalMachine"
                x509FindType="FindBySubjectName" storeName="My" />
            </peer>
            <issuedTokenAuthentication>
              <knownCertificates>
                <add findValue="CompanyXDev" storeLocation="LocalMachine" storeName="My"
                  x509FindType="FindBySubjectName" />
              </knownCertificates>
            </issuedTokenAuthentication>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

【问题讨论】:

  • 看起来您的服务主机配置有点过头了,不是吗?
  • Ladislav Mrnka 的评论让我发笑,+1。
  • 哦,看,又一个可怜的灵魂在追逐 RESTful 和 RPC 服务的神话概念。

标签: wcf rest ssl


【解决方案1】:

让我猜猜:您正在开发 Web 服务器 (Cassini) 中从 Visual Studio 运行您的服务,不是吗?开发 Web 服务器不支持 HTTPS。您必须在 IIS 中托管您的服务并按照 Greg 的建议为站点添加 HTTPS 绑定。

【讨论】:

    【解决方案2】:

    您需要在 IIS 中添加 https 绑定。

    1. 在 IIS 中导航到您的站点
    2. 点击右侧“操作”面板中的“绑定...”。
    3. 点击“添加”
    4. 选择“https”并选择证书。

    【讨论】:

      【解决方案3】:

      两个选择:

      1. 在端点中指定完整地址。

      2. 在标签的某处指定主机使用的基地址,例如:

      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8000/service"/>
          <add baseAddress="https://localhost:8001/service"/>
        </baseAddresses>
      </host>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-04
        • 1970-01-01
        • 2013-08-03
        相关资源
        最近更新 更多