WCF 服务的 basicHttpBinding 上的 HTTPS

发布于 2024-12-19 10:45:47 字数 2376 浏览 0 评论 0原文

我正在使用 IIS 7。在其上启用了 HTTPS 绑定,端口号为 443。我在网站下有一个 WCF 服务作为应用程序。我试图将 HTTPS 安全引入基于 http:// 的服务(使用 basicHttpBinding) msdn.microsoft.com/en-us/library/ms729700.aspx

我收到以下错误 – “提供的 URI 方案“https”无效;预期为“http”。”。当我检查事件日志时,它具有如下堆栈跟踪:

Stack Trace :    at System.ServiceModel.Channels.TransportChannelFactory`1.ValidateScheme(Uri via)

at System.ServiceModel.Channels.HttpChannelFactory.ValidateCreateChannelParameters(EndpointAddress remoteAddress, Uri via)

要使其在带有 basicHttpBinding 的 HTTPS 上工作需要进行哪些更改?

注意:证书是使用 IIS 7 中的“创建自签名证书”创建的。

 <system.serviceModel>

  <behaviors>
<serviceBehaviors>
  <behavior name="serviceFaultBehavior">
    <serviceMetadata httpGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="true"/>
  </behavior>
</serviceBehaviors>
  </behaviors>

  <services>
<service name="Business.TV.Clearance.Services.ServiceHandler"
         behaviorConfiguration="serviceFaultBehavior">
  <endpoint address=""
            binding="basicHttpBinding"
            contract="Business.TV.Clearance.Services.IServiceHandler"
            bindingConfiguration="httpBinding">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
</service>

  <bindings>
<basicHttpBinding>

  <binding name="httpBinding"
           maxReceivedMessageSize="2000000"
           maxBufferSize="2000000">

    <security mode="Transport">
      <transport clientCredentialType="Windows" />
    </security>


    <readerQuotas maxDepth="2147483647"
                  maxStringContentLength="2147483647"
                  maxArrayLength="2147483647" />
  </binding>
</basicHttpBinding>
  </bindings>

   <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

   <extensions>
 <behaviorExtensions>
  <add name="serviceFaultBehavior"
type="Business.TV.Clearance.Services.ServiceFaultBehaviorExtensionElement,Business.TV.Clearance.Services, Version=1.0.0.0, Culture=neutral"/>
</behaviorExtensions>
  </extensions>

</system.serviceModel>

I am using IIS 7. HTTPS binding is enabled on it with port number 443. I have a WCF service as an application under the website. I am trying to introduce HTTPS security to service (with basicHttpBinding) based on http://msdn.microsoft.com/en-us/library/ms729700.aspx

I am getting the following error – “The provided URI scheme 'https' is invalid; expected 'http'.”. When I checked the event log it has the stack trace as follows:

Stack Trace :    at System.ServiceModel.Channels.TransportChannelFactory`1.ValidateScheme(Uri via)

at System.ServiceModel.Channels.HttpChannelFactory.ValidateCreateChannelParameters(EndpointAddress remoteAddress, Uri via)

What is the change required to make it working on HTTPS with basicHttpBinding?

Note: Certificate is created using "Create Self Signed Certificate" in IIS 7.

 <system.serviceModel>

  <behaviors>
<serviceBehaviors>
  <behavior name="serviceFaultBehavior">
    <serviceMetadata httpGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="true"/>
  </behavior>
</serviceBehaviors>
  </behaviors>

  <services>
<service name="Business.TV.Clearance.Services.ServiceHandler"
         behaviorConfiguration="serviceFaultBehavior">
  <endpoint address=""
            binding="basicHttpBinding"
            contract="Business.TV.Clearance.Services.IServiceHandler"
            bindingConfiguration="httpBinding">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
</service>

  <bindings>
<basicHttpBinding>

  <binding name="httpBinding"
           maxReceivedMessageSize="2000000"
           maxBufferSize="2000000">

    <security mode="Transport">
      <transport clientCredentialType="Windows" />
    </security>


    <readerQuotas maxDepth="2147483647"
                  maxStringContentLength="2147483647"
                  maxArrayLength="2147483647" />
  </binding>
</basicHttpBinding>
  </bindings>

   <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

   <extensions>
 <behaviorExtensions>
  <add name="serviceFaultBehavior"
type="Business.TV.Clearance.Services.ServiceFaultBehaviorExtensionElement,Business.TV.Clearance.Services, Version=1.0.0.0, Culture=neutral"/>
</behaviorExtensions>
  </extensions>

</system.serviceModel>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

美人骨 2024-12-26 10:45:47

您需要将: 更改

<serviceMetadata httpGetEnabled="true" />

为:

<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />

You need to change:

<serviceMetadata httpGetEnabled="true" />

to:

<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
只等公子 2024-12-26 10:45:47

请尝试如下所示:

<service name="UserNameWithoutSSL.UsernameWithSSLService" behaviorConfiguration="TransportWithSecurity">
  <endpoint address="" binding="basicHttpBinding" bindingConfiguration="usernameViaSSL" contract="UserNameWithoutSSL.IUsernameWithSSLService">
    <identity>
      <dns value="localhost"/>
    </identity>
  </endpoint>
  <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
  <host>
    <baseAddresses>
      <add baseAddress="https://PCName/" />
    </baseAddresses>
  </host>
</service>

<basicHttpBinding>
  <binding name="usernameViaSSL">
    <security mode="TransportWithMessageCredential">
      <message clientCredentialType="UserName"/>
    </security>
  </binding>
</basicHttpBinding>

<serviceBehaviors>
  <behavior name="TransportWithSecurity">
    <serviceCredentials>
      <serviceCertificate findValue="localhost" storeLocation="LocalMachine"
        storeName="My" x509FindType="FindBySubjectName" />
      <userNameAuthentication userNamePasswordValidationMode="Windows" />
    </serviceCredentials>
    <serviceMetadata httpsGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="true" />
  </behavior>
</serviceBehaviors>

现在,在虚拟目录上的 IIS 上,您需要映射 443 以接受 Https 流量并分配一个用于保护传输层的证书。

Please try as shown below:

<service name="UserNameWithoutSSL.UsernameWithSSLService" behaviorConfiguration="TransportWithSecurity">
  <endpoint address="" binding="basicHttpBinding" bindingConfiguration="usernameViaSSL" contract="UserNameWithoutSSL.IUsernameWithSSLService">
    <identity>
      <dns value="localhost"/>
    </identity>
  </endpoint>
  <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
  <host>
    <baseAddresses>
      <add baseAddress="https://PCName/" />
    </baseAddresses>
  </host>
</service>

<basicHttpBinding>
  <binding name="usernameViaSSL">
    <security mode="TransportWithMessageCredential">
      <message clientCredentialType="UserName"/>
    </security>
  </binding>
</basicHttpBinding>

<serviceBehaviors>
  <behavior name="TransportWithSecurity">
    <serviceCredentials>
      <serviceCertificate findValue="localhost" storeLocation="LocalMachine"
        storeName="My" x509FindType="FindBySubjectName" />
      <userNameAuthentication userNamePasswordValidationMode="Windows" />
    </serviceCredentials>
    <serviceMetadata httpsGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="true" />
  </behavior>
</serviceBehaviors>

Now on your IIS on the virtual directory you need to have mapped 443 to accept Https traffic and assign a certificate that it needs to use for securing the transport layer.

做个ˇ局外人 2024-12-26 10:45:47

请尝试替换以下内容,这应该可行。

原文:

<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>

替换为:

<security mode="Transport">
<transport clientCredentialType="None" />
</security>

Please try to replace the below, this should work.

Original:

<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>

Replace with:

<security mode="Transport">
<transport clientCredentialType="None" />
</security>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文